Пример #1
0
/* store_result() - store record from database in B-tree
 * this function is also a valid callback for use with sqlite3_exec()
 * pextra is again unused
 *
 * needs to return zero (nonzero aborts SQL query)
 */
int store_result(void * pextra, int nfields, char ** arrvalues, char ** arrfieldnames) {
    int n;

    /* allocate record on heap */
    struct s_record * prec = alloc_record();


    prec->irecord = record_count+1;
    for (n = 0; n < nfields; n++) {
        if (strcasecmp(arrfieldnames[n], "MovieTitle") == 0)
            prec->name = strdup(arrvalues[n]); /* key */
        else if (strcasecmp(arrfieldnames[n], "MovieCategory") == 0)
            prec->category = strdup(arrvalues[n]);
        else if (strcasecmp(arrfieldnames[n], "ProductionYear") == 0)
            prec->year = atoi(arrvalues[n]);
        else if (strcasecmp(arrfieldnames[n], "Format") == 0)
            prec->format = strdup(arrvalues[n]);
        else if (strcasecmp(arrfieldnames[n], "Language") == 0)
            prec->language = strdup(arrvalues[n]);
        else if (strcasecmp(arrfieldnames[n], "Web") == 0)
            prec->url = strdup(arrvalues[n]);
    }

    /* add record to B-tree */
    if (add_element(prec->name, prec) != NULL) {
        /* element already exists -- don't add record */
        printf("Duplicate record exists: "); /* diagnostic value only */
        display_record(prec, stdout);
        free_record(prec);
    }

    return 0;
}
Пример #2
0
int locate_movie(char * title ) {
    struct s_record * pvalue;

    pvalue = find_value(title);
    if (pvalue != NULL) {
        printf("Found: ");
        display_record(pvalue, stdout);
    }
    return pvalue != NULL;
}
Пример #3
0
void food :: delete_item(void)
{
	clrscr() ;
	char t_code[5], ch ;
	int t, tcode ;
	gotoxy(3,25) ;
	cout <<"Press <ENTER> to see the list" ;
	gotoxy(5,3) ;
	cout <<"Enter Item Code of the item to be deleted : " ;
	gets(t_code) ;
	t = atoi(t_code) ;
	tcode = t ;
	if (t_code[0] == '0')
		return ;
	if (tcode == 0)
	{
		list_of_item() ;
		gotoxy(1,25) ; clreol() ;
		gotoxy(3,25) ;
		cout <<"Press <ENTER> to Exit" ;
		gotoxy(5,24) ;
		cout <<"Enter Item Code of the item to be deleted : " ;
		gets(t_code) ;
		t = atoi(t_code) ;
		tcode = t ;
		if (tcode == 0)
			return ;
	}
	clrscr() ;
	if (!item_found(tcode))
	{
		gotoxy(5,5) ;
		cout <<"\7Record not found" ;
		getch() ;
		return ;
	}
	display_record(tcode) ;
	do
	{
		gotoxy(1,8) ; clreol() ;
		gotoxy(5,8) ;
		cout <<"Do you want to delete this record (y/n) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
	} while (ch != 'N' && ch != 'Y') ;
	if (ch == 'N')
		return ;
	delete_record(tcode) ;
	gotoxy(5,15) ;
	cout <<"\7Record Deleted" ;
	getch() ;
}
Пример #4
0
void table_display ( tbl_p t )
{
  if (t == NULL) return;
  display_tbl_header (t);
  
  schema_p s = t->sch;
  record rec = new_record ( s );
  set_tbl_position ( t, TBL_BEG );
  while ( get_record (rec, s) )
    {
      display_record (rec, s);
    }
  put_msg (FORCE, "\n");

  release_record (rec, s);
}
Пример #5
0
Файл: raw.c Проект: scrime/FoB
int
main (int argc, char ** argv)
{
  unsigned char command;
  flock_response_t response;
  flock_t flock;
  int i;

  flock_init ();

  /* Opening flock with non blocking behavior. */
  fprintf (stderr, "Opening flock.\n");
  flock = flock_open ("/dev/ttyS0", O_NDELAY, NUMBER_OF_BIRDS);

  if (flock == NULL)
    {
      fprintf (stderr, "main: flock_make failed\n");
      exit (EXIT_FAILURE);
    }

  /* Examining whole flock status. */
  fprintf (stderr, "Getting flock status.\n");
  flock_command_display (stderr, flock_status);
  flock_write (flock, flock_status, 2);

  sleep (1);

  /* Trying super-expanded mode response.  (O_NDELAY (non blocking
     mode) required.) */
  fprintf (stderr, "  Trying super-expanded mode.\n");
  response = flock_read (flock, 126);

  if (response->size == -1)
    {
      /* Trying expanded mode response-> */
      fprintf (stderr, "  Trying expanded mode.\n");
      response = flock_read (flock, 30);
    }

  if (response->size == -1)
    {
      /* Trying normal mode response-> */
      fprintf (stderr, "  Trying normal mode.\n");
      response = flock_read (flock, 14);
    }

  if (response->size <= 0)
    {
      fprintf (stderr,
	       "main: getting flock status failed (are birds flying?)\n");
      return EXIT_FAILURE;
    }

  display_response (response);

  /* Getting status of master bird. */

#define MASTER_ADDRESS 1

  fprintf (stderr, "Getting status of bird #%d.\n", MASTER_ADDRESS);

  command = FLOCK_COMMAND_RS232_TO_FBB | MASTER_ADDRESS;

  flock_command_display (stderr, &command);
  flock_write (flock, &command, 1);

  flock_command_display (stderr, bird_status);
  flock_write (flock, bird_status, 2);

  sleep (1);
  response = flock_read (flock, 2);

  if (response->size <= 0)
    {
      fprintf (stderr,
	       "main: getting status of bird #%d failed (is bird flying?)\n",
	       MASTER_ADDRESS);
      return EXIT_FAILURE;
    }

  display_response (response);

  /* Getting status of slave bird. */

#define SLAVE_ADDRESS 2

  fprintf (stderr, "Getting status of bird #%d.\n", SLAVE_ADDRESS);

  command = FLOCK_COMMAND_RS232_TO_FBB | SLAVE_ADDRESS;

  flock_command_display (stderr, &command);
  flock_write (flock, &command, 1);

  flock_command_display (stderr, bird_status);
  flock_write (flock, bird_status, 2);

  sleep (1);
  response = flock_read (flock, 2);

  if (response->size <= 0)
    {
      fprintf (stderr,
	       "main: getting status of bird #%d failed (is bird flying?)\n",
	       SLAVE_ADDRESS);
      return EXIT_FAILURE;
    }

  display_response (response);

  /* Auto configuration. */
  fprintf (stderr, "Auto configuring.\n");
  flock_command_display (stderr, auto_config);
  flock_write (flock, auto_config, 3);
  sleep (1);

  /* Examining group mode. */
  fprintf (stderr, "Getting current group mode.\n");
  flock_command_display (stderr, examine_group_mode);
  flock_write (flock, examine_group_mode, 2);

  sleep (1);
  response = flock_read (flock, 1);
  display_response (response);

  /* Setting group mode. */
  fprintf (stderr, "Setting group mode.\n");
  flock_command_display (stderr, set_group_mode);
  flock_write (flock, set_group_mode, 3);

  /* Getting records. */

#define NUMBER_OF_RECORDS 10
#define SIZEOF_RECORD 26

  fprintf (stderr, "Getting %d records.\n", NUMBER_OF_RECORDS);

  for (i = 0; i < NUMBER_OF_RECORDS; i++)
    {
      struct flock_bird_record_s rec;
      double t1, t2;

      flock_command_display (stderr, point);
      flock_write (flock, point, 1);

      t1 = now ();

      /* Active loop. (Generally bad, especially when device was
         opened in non-blocking mode, but this is only a test.) */
      while (1)
	{
	  response = flock_read (flock, SIZEOF_RECORD);

	  if (response == NULL)
	    {
	      perror ("flock_read");
	      exit (EXIT_FAILURE);
	    }

	  if (response->size != -1)
	    break;
	}

      t2 = now ();

      fprintf (stderr, "waited %.0f ms\n", t2 - t1);

      display_response (response);

      /* Position of master. */
      flock_bird_record_fill (&rec,
			      response->data,
			      flock_bird_record_mode_position_angles);
      display_record (&rec);

      /* Position of slave. */
      flock_bird_record_fill (&rec,
			      response->data + (SIZEOF_RECORD / 2),
			      flock_bird_record_mode_position_angles);
      display_record (&rec);
    }

  /* Closing flock. */
  fprintf (stderr, "Closing flock.\n");
  flock_close (flock);

  return EXIT_SUCCESS;
}
Пример #6
0
void food :: purchase(void)
{
	clrscr() ;
	account a ;
	int t_billno, purchased=0 ;
	t_billno = a.last_billno() ;
	t_billno++ ;
	char t_code[5], ch, t_quantity[5] ;
	int t, tcode, i=0, valid ;
	float qty ;
	int t_itemcode ;
	float t_qty, t_cost, t_price ;
	char t_itemname[30] ;
	struct date d;
	int d1, m1, y1 ;
	getdate(&d);
	d1 = d.da_day ;
	m1 = d.da_mon ;
	y1 = d.da_year ;
	do
	{
		clrscr() ;
		gotoxy(3,25) ;
		cout <<"Press <ENTER> to see the list" ;
		gotoxy(5,3) ;
		cout <<"Enter Item Code of the item to be Purchase : " ;
		gets(t_code) ;
		t = atoi(t_code) ;
		tcode = t ;
		if (t_code[0] == '0')
		{
			if (purchased)
				a.prepare_bill(t_billno) ;
			return ;
		}
		if (tcode == 0)
		{
			list_of_item() ;
			gotoxy(1,25) ; clreol() ;
			gotoxy(3,25) ;
			cout <<"Press <ENTER> to Exit" ;
			gotoxy(5,24) ;
			cout <<"Enter Item Code of the item to be Purchase : " ;
			gets(t_code) ;
			t = atoi(t_code) ;
			tcode = t ;
			if (tcode == 0)
			{
				if (purchased)
					a.prepare_bill(t_billno) ;
				return ;
			}
		}
		clrscr() ;
		if (!item_found(tcode))
		{
			gotoxy(5,5) ;
			cout <<"\7Item Code not found" ;
			getch() ;
			if (purchased)
				a.prepare_bill(t_billno) ;
			return ;
		}
		gotoxy(60,2) ;
		cout <<"Date:" <<d1 <<"/" <<m1 <<"/" <<y1 ;
		display_record(tcode) ;
		do
		{
			valid = 1 ;
			gotoxy(1,8) ; clreol() ;
			gotoxy(1,24) ; clreol() ;
			gotoxy(1,25) ; clreol() ;
			gotoxy(3,25) ;
			cout <<"ENTER QUANTITY TO BE PURCHASE IN Kg." ;
			gotoxy(5,8) ;
			cout <<"Quantity : " ;
			gets(t_quantity) ;
			qty = atoi(t_quantity) ;
			if (t_quantity[0] == '0')
			{
				if (purchased)
					a.prepare_bill(t_billno) ;
				return ;
			}
			if (qty < 1 || qty > 800)
			{
				valid = 0 ;
				gotoxy(3,24) ;
				cout <<"\7 Range = 1..800" ;
				getch() ;
			}
		} while (!valid) ;
		do
		{
			gotoxy(5,10) ; clreol() ;
			gotoxy(5,10) ;
			cout <<"Do you want to cancel this purchase (y/n) : " ;
			ch = getche() ;
			ch = toupper(ch) ;
		} while (ch != 'N' && ch != 'Y') ;
		if (ch == 'N')
		{
			purchased = 1 ;
			fstream file ;
			file.open("FOOD.DAT", ios::in) ;
			file.seekg(0,ios::beg) ;
			while (file.read((char *) this, sizeof(food)))
			{
				if (itemcode == tcode)
				{
					t_itemcode = itemcode ;
					strcpy(t_itemname,itemname) ;
					t_cost = itemcost ;
					t_price = itemprice ;
					t_qty = qty ;
					a.add_bill(t_billno,t_itemcode,t_itemname,t_qty,t_cost,t_price) ;
					i++ ;
					break ;
				}
			}
			file.close() ;
		}
		do
		{
			gotoxy(5,12) ; clreol() ;
			gotoxy(5,12) ;
			cout <<"Do you want to purchase more (y/n) : " ;
			ch = getche() ;
			ch = toupper(ch) ;
		} while (ch != 'N' && ch != 'Y') ;
	} while (ch == 'Y') ;
	a.prepare_bill(t_billno) ;
}
Пример #7
0
int main(void) {
    int userInput;
    size_t i;
    record student_record;
    name student_name;
    record_list student_list; 
    student_list.nalloc = 0;
    student_list.nused = 0;

    list_init(&student_list);
    do {
        displayMenu();
        userInput = get_user_input();
        
        if(userInput == ENTER_RECORDS) {
            while (userInput != EOF) {
                while (userInput != EOF && ask_for_student_id(&student_record, &userInput)) {
                    ;
                }
                while(userInput != EOF && ask_for_last_name(&student_name, &userInput)) {
                    ;
                }
                while (userInput != EOF && ask_for_first_name(&student_name, &userInput)) {
                    ;
                }

                while (userInput != EOF && ask_for_score(&student_record, &userInput)) {
                    ;
                }
                if (userInput != EOF) {
                    student_record.name = student_name;
                    list_insert(&student_list, &student_record);
                    fprintf(stderr, "Please enter another record.\n");
                }
            }
        }
        if (userInput == RECORDS_BY_ID) {
            if (student_list.nused == 0) {
                fprintf(stderr, "No data to display.\n");
            } else {
                qsort(student_list.data, student_list.nused, sizeof(student_list.data[0]), cmp_by_id);
                for (i = 0; i < student_list.nused; i++) {
                    display_record(student_list.data[i]);
                }
            }
        }
        
        if (userInput == RECORDS_BY_NAME) {
            if (student_list.nused == 0) {
                fprintf(stderr, "No data to display.\n");
            } else {
                qsort(student_list.data, student_list.nused, sizeof(student_list.data[0]), cmp_by_name);
                for (i = 0; i < student_list.nused; i++) {
                    display_record(student_list.data[i]);
                }
            }
        }
        
    } while (userInput != QUIT);
    
    list_destroy(&student_list);
    return 0;
}