コード例 #1
0
static void DeleteList()//START PROBLEM 3
{
	int boolean = 1;
	int content;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			AppendNode(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}

	//Now delete the list
	if(yesno("Would you like to delete the list (Y/N)?"))
	{
		Delete_List(&head);
	}
	if(head == NULL)
	{
		printf("The head node has been set to NULL.\n");
	}
}//END PROBLEM 3
コード例 #2
0
ファイル: str.cpp プロジェクト: ftnapps/pkg-sbbs
void sbbs_t::sys_info()
{
	char	tmp[128];
	uint	i;
	stats_t stats;

	bputs(text[SiHdr]);
	getstats(&cfg,0,&stats);
	bprintf(text[SiSysName],cfg.sys_name);
	bprintf(text[SiSysID],cfg.sys_id);	/* QWK ID */
	for(i=0;i<cfg.total_faddrs;i++)
		bprintf(text[SiSysFaddr],smb_faddrtoa(&cfg.faddr[i],tmp));
	if(cfg.sys_psname[0])				/* PostLink/PCRelay */
		bprintf(text[SiSysPsite],cfg.sys_psname,cfg.sys_psnum);
	bprintf(text[SiSysLocation],cfg.sys_location);
	bprintf(text[SiSysop],cfg.sys_op);
	bprintf(text[SiSysNodes],cfg.sys_nodes);
//	bprintf(text[SiNodeNumberName],cfg.node_num,cfg.node_name);
	bprintf(text[SiNodePhone],cfg.node_phone);
	bprintf(text[SiTotalLogons],ultoac(stats.logons,tmp));
	bprintf(text[SiLogonsToday],ultoac(stats.ltoday,tmp));
	bprintf(text[SiTotalTime],ultoac(stats.timeon,tmp));
	bprintf(text[SiTimeToday],ultoac(stats.ttoday,tmp));
	ver();
	if(yesno(text[ViewSysInfoFileQ])) {
		CLS;
		sprintf(tmp,"%ssystem.msg", cfg.text_dir);
		printfile(tmp,0); 
	}
	if(yesno(text[ViewLogonMsgQ])) {
		CLS;
		menu("logon"); 
	}
}
コード例 #3
0
static void InsertNth()//PROBLEM 5
{
	int boolean = 1;
	int content;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Push(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}

	boolean = 1; //reset boolean to default to prepare for next while loop

	while(boolean)
	{
		short int boolean2;
		short int boolean3 = 1;
		int value = 0;
		if(yesno("Would you like to insert a new node at an arbitrary position (Y/N)?"))
		{
			read_int("Enter the position for which you want to insert the node: ", &content);
			Insert_Nth(&head, content);
			printf("Now let's check the contents of the list.\n");
			while(boolean3)
			{
				read_int("Please enter your value to search for: ", &content);
				boolean2 = GetValue(head, content, &value);
				if(boolean2 == 0)
				{
					printf("The list is either empty or the value you entered is out of range.\n");
				}
				else
				{
					printf("The value of element %d is %d.\n", content, value);
				}
				if(!yesno("Do you want to search for another value of an element (Y/N)?"))
				{
					boolean3 = 0;
				}
			}
		}
		else
		{
			boolean = 0;
		}
	}
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 5
コード例 #4
0
int main(void)
{
    const uint8_t *json = (uint8_t*)"{ \"message\" : \"Hello World!\" }";
    bson_error_t error;
    bson_t *doc;
    char *str;
    size_t len;

    if (!(doc = bson_new_from_json(json, -1, &error)))
    {
        fprintf(stderr, "Cannot initialize BSON structure from JSON example.\n");
        fprintf(stderr, "BSON error message: %s\n", error.message);

        return 1;
    }

    printf("Has key \"message\" (expect \"yes\")   : %s\n", yesno(bson_has_field(doc, "message")));
    printf("Has key \"triceratops\" (expect\"no\") : %s\n", yesno(bson_has_field(doc, "triceratops")));

    str = bson_as_json(doc, &len);
    printf("Original JSON document  : %s\n", json);
    printf("BSON-to-JSON conversion : %s\n", str);
    bson_free(str);

    bson_destroy(doc);

    return 0;
}
コード例 #5
0
static void SortedIntersection()//PROBLEM 16
{
	int boolean = 1;
	int content;
	struct node *Ahead = NULL;
	struct node *Bhead = NULL;
	struct node *Chead = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value for Ahead (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Push(&Ahead, content);
		}
		else
		{
			boolean = 0;
		}
		Insert_Sort(&Ahead);
	}

	boolean = 1;
	while(boolean)
	{
		if(yesno("Would you like to enter a value for Bhead (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Push(&Bhead, content);
		}
		else
		{
			boolean = 0;
		}
		Insert_Sort(&Bhead);
	}
	PrintListData(Ahead);
	PrintListData(Bhead);
	PrintListData(Chead);
	Sorted_Intersection(&Ahead, &Bhead, &Chead);
	PrintListData(Ahead);
	PrintListData(Bhead);
	PrintListData(Chead);
	freeElements(&Ahead);//free up the allocated memory
	if(Ahead == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
	freeElements(&Bhead);//free up the allocated memory
	if(Bhead == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
	freeElements(&Chead);//free up the allocated memory
	if(Chead == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 16
コード例 #6
0
static void ISBST()//PROBLEM 13 and 14
{
	int boolean = 1;
	struct node *head = NULL;
	int content;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Append(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}
	if(head == NULL)
	{
		printf("The tree is empty.\n");
		return;
	}
	Is_Search_Tree(head);
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
	//Now enter the same nodes and make a non searchable tree
	boolean = 1;
	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			NonSearchableTree(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}
	if(head == NULL)
	{
		printf("The tree is empty.\n");
		return;
	}
	Is_Search_Tree(head);
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 13 and 14
コード例 #7
0
ファイル: edit.c プロジェクト: OPSF/uClinux
static void edit_bitmap(char *bitmap_file)
{
    char *cmd;
    int editing = 1;
    
    printf("Editing contents of bitmap file:  %s\n", bitmap_file);
    
    bmp_file_open(bitmap_file);

    do {
	show_layout();
	printf("\nText colors:\n");
	show_colors(0);
	show_timer();
	
	printf("\nCommands are:  L)ayout, C)olors, T)imer, Q)uit, W)rite:  ");
	cmd = getLine();
	switch(toupper(*cmd)) {
	    case 'C':
		edit_colors();
		break;
	    case 'L':
		edit_layout();
		break;
	    case 'T':
		edit_timer();
		break;
	    case 'W':
	        if (yesno("Save companion configuration file?", 0))
						dat_file_creat(bitmap_file);
	    	editing = !yesno("Save changes to bitmap file?", 0);
	    	if (!editing) {
	    	    printf("Writing output file:  %s\n", bitmap_file);
	    	    bmp_file_close(!test);  /* update */
	    	    if (test) printf("***The bitmap file has not been changed***\n");
		}
	    	break;
	    case 'Q':
	    	editing = !yesno("Abandon changes?", 0);
	    	if (!editing) bmp_file_close(0);  /* no update */
	    	break;
	    default:
	    	printf("???");
	}
	free(cmd);
	printf("\n");
    } while (editing);
    exit(0);
}
コード例 #8
0
static void GetNth()//START PROBLEM 2
{
	int boolean = 1;
	int content;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			AppendNode(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}

	boolean = 1; //reset boolean to default to prepare for next while loop

	while(boolean)
	{
		short int boolean2;
		int value = 0;
		if(yesno("Do you want to search for the value of an element (Y/N)?"))
		{
			read_int("Please enter your value to search for: ", &content);
			boolean2 = GetValue(head, content, &value);
			if(boolean2 == 0)
			{
				printf("The list is either empty or the value you entered is out of range.\n");
			}
			else
			{
				printf("The value of element %d is %d.\n", content, value);
			}
		}
		else
		{
			boolean = 0;
		}
	}
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 2
コード例 #9
0
ファイル: rooms.c プロジェクト: cafuego/monolith
void
reset_room()
{
    int roomnum;
    char *quad_name;
    room_t scratch;

    memset(&scratch, 0, sizeof(room_t));

    cprintf("Number of room to reset: ");
    quad_name = get_name(3);

    if (strlen(quad_name) < 1)
	return;

    roomnum = atoi(quad_name);

    scratch = readquad(roomnum);

    scratch.highest = 0;
    cprintf("Are you really sure you want to reset %s>?\n", scratch.name);
    if (yesno() == YES) {
	write_quad(scratch, roomnum);
	log_sysop_action("reset %s %d.%s>", config.forum, roomnum, scratch.name);
    } else {
	cprintf("Ok then. No resetting done this time.\n\n");
    }
    return;
}
コード例 #10
0
ファイル: files.c プロジェクト: astrotycoon/grace
/* open a file for write */
FILE *gapp_openw(GraceApp *gapp, const char *fn)
{
    struct stat statb;
    char buf[GR_MAXPATHLEN + 50];
    FILE *retval;

    if (!fn || !fn[0]) {
        errmsg("No file name given");
	return NULL;
    } else if (strcmp(fn, "-") == 0 || strcmp(fn, "stdout") == 0) {
        return stdout;
    } else {
        if (stat(fn, &statb) == 0) {
            /* check to make sure this is a file and not a dir */
            if (S_ISREG(statb.st_mode)) {
	        sprintf(buf, "Overwrite %s?", fn);
	        if (!yesno(buf, NULL, NULL, NULL)) {
	            return NULL;
	        }
            } else {
                sprintf(buf, "%s is not a regular file!", fn);
                errmsg(buf);
	        return NULL;
            }
        }
        retval = filter_write(gapp, fn);
        if (!retval) {
	    sprintf(buf, "Can't write to file %s, check permissions!", fn);
            errmsg(buf);
        }
        return retval;
    }
}
コード例 #11
0
static void MinValue()//PROBLEM 4
{
	int boolean = 1;
	int content;
	int minvalue = 0;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Append(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}

	minvalue = Min_Value(head);
	printf("The depth of the tree is %d.\n", minvalue);
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 4
コード例 #12
0
ファイル: gfledit.cpp プロジェクト: bhaggerty/wwiv-1
void gfileedit() {
  int i;
  char s[81];

  if (!ValidateSysopPassword()) {
    return;
  }
  showsec();
  bool done = false;
  do {
    bout.nl();
    bout << "|#2G-files: D:elete, I:nsert, M:odify, Q:uit, ? : ";
    char ch = onek("QDIM?");
    switch (ch) {
    case '?':
      showsec();
      break;
    case 'Q':
      done = true;
      break;
    case 'M':
      bout.nl();
      bout << "|#2Section number? ";
      input(s, 2);
      i = atoi(s);
      if ((s[0] != 0) && (i >= 0) && (i < session()->num_sec)) {
        modify_sec(i);
      }
      break;
    case 'I':
      if (session()->num_sec < session()->max_gfilesec) {
        bout.nl();
        bout << "|#2Insert before which section? ";
        input(s, 2);
        i = atoi(s);
        if ((s[0] != 0) && (i >= 0) && (i <= session()->num_sec)) {
          insert_sec(i);
        }
      }
      break;
    case 'D':
      bout.nl();
      bout << "|#2Delete which section? ";
      input(s, 2);
      i = atoi(s);
      if ((s[0] != 0) && (i >= 0) && (i < session()->num_sec)) {
        bout.nl();
        bout << "|#5Delete " << gfilesec[i].name << "?";
        if (yesno()) {
          delete_sec(i);
        }
      }
      break;
    }
  } while (!done && !hangup);
  File gfileDat(syscfg.datadir, GFILE_DAT);
  gfileDat.Open(File::modeReadWrite | File::modeBinary | File::modeCreateFile | File::modeTruncate);
  gfileDat.Write(&gfilesec[0], session()->num_sec * sizeof(gfiledirrec));
  gfileDat.Close();
}
コード例 #13
0
static void DoubleTree()//PROBLEM 10
{
	int boolean = 1;
	int content;
	int depth;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Append(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}
	if(head == NULL)
	{
		printf("The tree is empty.\n");
		return;
	}
	depth = Max_Depth(head);
	Print_Paths(head, depth);
	Double_Tree(head);
	Print_Paths(head, depth);
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 10
コード例 #14
0
static void PrintTree()//PROBLEM 5
{
	int boolean = 1;
	int content;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Append(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}

	Print_Tree(head);
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 5
コード例 #15
0
ファイル: fido.cpp プロジェクト: K6BSD/SBBSUnstable
bool sbbs_t::lookup_netuser(char *into)
{
	char to[128],name[26],str[256],q[128];
	int i;
	FILE *stream;

	if(strchr(into,'@'))
		return(false);
	strcpy(to,into);
	strupr(to);
	sprintf(str,"%sqnet/users.dat", cfg.data_dir);
	if((stream=fnopen(&i,str,O_RDONLY))==NULL)
		return(false);
	while(!feof(stream)) {
		if(!fgets(str,sizeof(str),stream))
			break;
		str[25]=0;
		truncsp(str);
		strcpy(name,str);
		strupr(name);
		str[35]=0;
		truncsp(str+27);
		sprintf(q,"Do you mean %s @%s",str,str+27);
		if(strstr(name,to) && yesno(q)) {
			fclose(stream);
			sprintf(into,"%s@%s",str,str+27);
			return(true); 
		}
		if(sys_status&SS_ABORT)
			break; 
	}
	fclose(stream);
	return(false);
}
コード例 #16
0
ファイル: setup.c プロジェクト: zcw159357/citadel
/*
 * On systems which use xinetd, see if we can offer to install Citadel as
 * the default telnet target.
 */
void check_xinetd_entry(void)
{
    char *filename = "/etc/xinetd.d/telnet";
    FILE *fp;
    char buf[SIZ];
    int already_citadel = 0;
    int rv;

    fp = fopen(filename, "r+");
    if (fp == NULL) return;		/* Not there.  Oh well... */

    while (fgets(buf, sizeof buf, fp) != NULL) {
        if (strstr(buf, "/citadel") != NULL) {
            already_citadel = 1;
        }
    }
    fclose(fp);
    if (already_citadel) return;	/* Already set up this way. */

    /* Otherwise, prompt the user to create an entry. */
    if (getenv("CREATE_XINETD_ENTRY") != NULL) {
        if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
            return;
        }
    }
    else {
        snprintf(buf, sizeof buf,
                 _("Setup can configure the \"xinetd\" service to automatically\n"
                   "connect incoming telnet sessions to Citadel, bypassing the\n"
                   "host system login: prompt.  Would you like to do this?\n"
                  )
                );
        if (yesno(buf, 1) == 0) {
            return;
        }
    }

    fp = fopen(filename, "w");
    fprintf(fp,
            "# description: telnet service for Citadel users\n"
            "service telnet\n"
            "{\n"
            "	disable	= no\n"
            "	flags		= REUSE\n"
            "	socket_type	= stream\n"
            "	wait		= no\n"
            "	user		= root\n"
            "	server		= /usr/sbin/in.telnetd\n"
            "	server_args	= -h -L %s/citadel\n"
            "	log_on_failure	+= USERID\n"
            "}\n",
            ctdl_bin_dir);
    fclose(fp);

    /* Now try to restart the service */
    rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
    if (rv != 0) {
        display_error(_("failed to restart xinetd.\n"));
    }
}
コード例 #17
0
void StudentDlg::OnOK() 
{
	//Update the currently changed data
	UpdateData();
	if (curselection!=-1) student->SetPropertyValue(curselection, m_CPropertyValueText);
	UpdateData(FALSE);

	if (student->GetPropertyValue("Name")=="" || 
		student->GetPropertyValue("Name").FindOneOf("\\") >= 0 )
	{
		MessageBox("The student must have a name to be created.");
		curselection = 0;
		m_proplist.SetCurSel(curselection);
		CString valuetext = student->GetPropertyValue(curselection);
		m_CPropertyValue.SetWindowText(valuetext);
		//Set the focus on the property text
		m_CPropertyValue.SetFocus();
		return;
	}

	//Ask if the user would like to add another student
	if (addanother != NULL) 
	{
		YESNODlg yesno(NULL, "Do you wish to add another student at this time?", addanother);
		yesno.DoModal();
	}
	CDialog::OnOK();
}
コード例 #18
0
ファイル: delete.c プロジェクト: CadeLaRen/illumos-gate
static KMF_RETURN
pk_delete_certs(KMF_HANDLE_T kmfhandle, KMF_ATTRIBUTE *attlist, int numattr)
{
	KMF_RETURN rv = KMF_OK;
	uint32_t numcerts = 0;
	int num = numattr;

	kmf_set_attr_at_index(attlist, num,
	    KMF_COUNT_ATTR, &numcerts, sizeof (uint32_t));
	num++;

	rv = kmf_find_cert(kmfhandle, num, attlist);
	if (rv == KMF_OK && numcerts > 0) {
		char prompt[1024];
		(void) snprintf(prompt, sizeof (prompt),
		    gettext("%d certificate(s) found, do you want "
		    "to delete them (y/N) ?"), numcerts);

		if (!yesno(prompt,
		    gettext("Respond with yes or no.\n"),
		    B_FALSE)) {
			return (KMF_OK);
		}

		/*
		 * Use numattr because delete cert does not require
		 * KMF_COUNT_ATTR attribute.
		 */
		rv = kmf_delete_cert_from_keystore(kmfhandle, numattr, attlist);

	}

	return (rv);
}
コード例 #19
0
ファイル: MAIN.C プロジェクト: Kolahzary/csale
void edit() /* This function will edit an existing record */
{
	int index;
	struct product tempProduct;
	unsigned int oldcode=0;
	do{
		clrscr();
		puts("\t\t\tProduct Edit\n\n\n");

		oldcode=getExistingCode("Enter Code of product to Edit(0 for cancel): "); // Get a valid Code, This is previous code
		if(oldcode==0) return; // if 0 was entered, return to main menu
		index=getIndexByCode(oldcode);	// Get index of valid code

				tempProduct.code	=	getNewCode("Enter a new code for change between 0 and 65535: ")					;	// Get a valid Code, This is new code
		strcpy(	tempProduct.name	,	getNewName("Enter a new name for change without spaces (max 50 characters): ")	);	// Get a valid Name
				tempProduct.price	=	getNewPrice("Enter a new price for change between 0 and 4294967295: ")			;	// Get a valid Price

				arrMain[index].code		=	tempProduct.code	;		// Put code into main array
		strcpy(	arrMain[index].name		,	tempProduct.name	);		// Put name into main array
				arrMain[index].price	=	tempProduct.price	;		// Put price into main array

		puts("\n Saved...");			// Record Edited, tell user
	}while(yesno("Do you want to edit a new product? ")==true);
	getch();		// wait...
}
コード例 #20
0
// setBoardParam: Set the board Id string, mac addresses, psi size, etc...
//
int setBoardParam(void)
{
    int bChange = FALSE;
    int count = 0;
    PPARAMETER_SETTING tmpPtr = gBoardParam;    
    int memType;

    while (tmpPtr->promptName !=  NULL)
    {
        count++;
        tmpPtr++;
    }

    getBoardParam();

    while (1)
    {
        bChange = processPrompt(gBoardParam, count);
        if (strlen(gBoardParam[3].parameter) != 0)
            break;
        printf("Base Mac address is not entered.  Try it again!\n");
    }

    if (bChange)
    {
        // fill in board id string, psi and mac count
        nvramData.ulVersion = NVRAM_VERSION_NUMBER;
        nvramData.ulEnetModeFlag = 0xffffffff;          // all ffs for enet mode flag
        memset(nvramData.szBoardId, 0, NVRAM_BOARD_ID_STRING_LEN);
        memcpy(nvramData.szBoardId, gBoardParam[0].parameter, NVRAM_BOARD_ID_STRING_LEN);
        nvramData.ulPsiSize = atoi(gBoardParam[1].parameter);
        nvramData.ulNumMacAddrs = atoi(gBoardParam[2].parameter);
        parsehwaddr(gBoardParam[3].parameter, nvramData.ucaBaseMacAddr);

        // set memory type thing
        memType = atoi(gBoardParam[4].parameter);
        kerSysMemoryTypeSet((int) FLASH63XX_ADDR_BOOT_ROM, (char *)&memType, sizeof(int));

        if (nvramData.ulPsiSize != NVRAM_PSI_DEFAULT_6345)
        {
            printf("Are you REALLY sure persistent storage size is %d?", nvramData.ulPsiSize);
            if (yesno())
            {
                nvramData.ulPsiSize = NVRAM_PSI_DEFAULT_6345;
                sprintf(gBoardParam[1].parameter, "%d", nvramData.ulPsiSize);
                return 0;
            }
        }
        // save the buf to nvram
        writeNvramData();

        printf("Press any key to reset the board: \n");
        while (1)
            if (console_status())
                kerSysMipsSoftReset();
    }

    return 0;

}  // setBoardParam
コード例 #21
0
static void RecursionReverse()//PROBLEM 18
{
	int boolean = 1;
	int content;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Push(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}
	PrintListData(head);
	Recursion_Reverse(&head);
	PrintListData(head);
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 18
コード例 #22
0
static void MergeSort()//PROBLEM 15
{
	int boolean = 1;
	int content;
	struct node *Ahead = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value for Ahead (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Push(&Ahead, content);
		}
		else
		{
			boolean = 0;
		}
	}

	PrintListData(Ahead);
	Merge_Sort(&Ahead);
	PrintListData(Ahead);
	freeElements(&Ahead);//free up the allocated memory
	if(Ahead == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 14
コード例 #23
0
ファイル: test-yesno.c プロジェクト: ajnelson/gnulib
/* Test yesno.  Without arguments, read one line.  If first argument
   is zero, close stdin before attempting to read one line.
   Otherwise, read the number of lines specified by first
   argument.  */
int
main (int argc, char **argv)
{
  int i = 1;
  program_name = argv[0];

  /* yesno recommends that all clients use close_stdin in main.  */
  atexit (close_stdin);
  /* But on mingw, close_stdin leaves stdin's file descriptor at the expected
     position (i.e. where this program left off reading) only if its mode has
     been set to O_BINARY.  If it has been set to O_TEXT, and the file
     descriptor is seekable, and stdin is buffered, the MSVCRT runtime ends up
     setting the file descriptor's position to the expected position _minus_
     the number of LFs not preceded by CR that were read between the expected
     position and the last filled buffer end position.  (I.e. the repositioning
     from the end-of-buffer to the expected position does not work if the input
     file contains end-of-line markers in Unix convention.)  */
  SET_BINARY (0);

  if (1 < argc)
    i = atoi (argv[1]);
  if (!i)
    {
      i = 1;
      close (0);
    }
  while (i--)
    puts (yesno () ? "Y" : "N");
  return 0;
}
コード例 #24
0
ファイル: explorer.c プロジェクト: mariusal/grace
static void project_popup_any_cb(ExplorerUI *eui, int type)
{
    TreeItemList items;
    Quark *q;
    GraceApp *gapp;
    GProject *gp;

    TreeGetHighlighted(eui->tree, &items);

    if (!items.count || items.count > 1) {
        xfree(items.items);
        return;
    }

    q = TreeGetQuark(items.items[0]);
    gapp = gapp_from_quark(q);
    gp = gproject_from_quark(q);

    switch (type) {
    case PROJECT_SHOW_CB:
        gapp_set_active_gproject(gapp, gp);
        xdrawgraph(gp);
        update_all();
        break;
    case PROJECT_SAVE_CB:
        project_save(gp);
        break;
    case PROJECT_SAVE_AS_CB:
        project_save_as(gp);
        break;
    case PROJECT_REVERT_TO_SAVED_CB:
        revert_project(gapp, gp);
        xdrawgraph(gapp->gp);
        update_all();
        break;
    case PROJECT_CLOSE_CB:
        if (gapp->gpcount == 1) {
            errmsg("Can't close the last project");
            return;
        }

        if (gp && gproject_get_top(gp) &&
            quark_dirtystate_get(gproject_get_top(gp)) &&
            !yesno("Abandon unsaved changes?", NULL, NULL, NULL)) {
            return;
        }

        gapp_delete_gproject(gapp, gp);

        if (gapp->gp == NULL) {
            gapp_set_active_gproject(gapp, gapp->gplist[0]);
        }

        xdrawgraph(gapp->gp);
        update_all();
        break;
    }

    xfree(items.items);
}
コード例 #25
0
ファイル: sha-perf.c プロジェクト: linaro-swg/sha-perf
/* Hash test: buffer of size byte. Run test n times. */
static void run_test(size_t size, unsigned int n, unsigned int l)
{
	uint64_t t;
	struct statistics stats;
	TEEC_Operation op;
	int n0 = n;

	alloc_shm(size, algo);

	if (!random_in)
		memset((uint8_t *)in_shm.buffer + offset, 0, size);

	memset(&op, 0, sizeof(op));
	op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
					 TEEC_MEMREF_PARTIAL_OUTPUT,
					 TEEC_VALUE_INPUT, TEEC_NONE);
	op.params[0].memref.parent = &in_shm;
	op.params[0].memref.offset = 0;
	op.params[0].memref.size = size + offset;
	op.params[1].memref.parent = &out_shm;
	op.params[1].memref.offset = 0;
	op.params[1].memref.size = hash_size(algo);
	op.params[2].value.a = l;
	op.params[2].value.b = offset;

	verbose("Starting test: %s, size=%zu bytes, ",
		algo_str(algo), size);
	verbose("random=%s, ", yesno(random_in));
	verbose("unaligned=%s, ", yesno(offset));
	verbose("inner loops=%u, loops=%u, warm-up=%u s\n", l, n, warmup);

	if (warmup)
		do_warmup();

	memset(&stats, 0, sizeof(stats));
	while (n-- > 0) {
		t = run_test_once((uint8_t *)in_shm.buffer + offset, size, &op, l);
		update_stats(&stats, t);
		if (n % (n0/10) == 0)
			vverbose("#");
	}
	vverbose("\n");
	printf("min=%gμs max=%gμs mean=%gμs stddev=%gμs (%gMiB/s)\n",
	       stats.min/1000, stats.max/1000, stats.m/1000,
	       stddev(&stats)/1000, mb_per_sec(size, stats.m));
	free_shm();
}
コード例 #26
0
ファイル: files.c プロジェクト: astrotycoon/grace
static int load_project_file(GraceApp *gapp, const char *fn, int as_template)
{    
    GProject *gp;
    Quark *project, *gr, **graphs;
    int i, ngraphs;
    AMem *amem;

    if (gapp->gp && gproject_get_top(gapp->gp) &&
        quark_dirtystate_get(gproject_get_top(gapp->gp)) &&
        !yesno("Abandon unsaved changes?", NULL, NULL, NULL)) {
        return RETURN_FAILURE;
    }
    
    gproject_free(gapp->gp);

    gp = load_any_project(gapp, fn);
    if (!gp) {
        errmsg("Failed loading project file");
        return RETURN_FAILURE;
    }
    
    project = gproject_get_top(gp);

    gapp->rt->print_file[0] = '\0';

    gapp_set_project(gapp, gp);

    if (as_template) {
        grfile_free(gp->grf);
        gp->grf = NULL;
    }

    amem = quark_get_amem(project);

    /* Set undo limit of 16MB */
    amem_set_undo_limit(amem, 0x1000000L);
    /* Get initial memory snapshot */
    amem_snapshot(amem);

    /* try to switch to the first active graph */
    ngraphs = project_get_graphs(project, &graphs);
    for (i = 0; i < ngraphs; i++) {
        gr = graphs[i];
        if (select_graph(gr) == RETURN_SUCCESS) {
            break;
        }
    }
    xfree(graphs);

#ifndef NONE_GUI
    select_quark_explorer(project);
    update_all();
#endif
    if (project) {
        return RETURN_SUCCESS;
    } else {
        return RETURN_FAILURE;
    }
}
コード例 #27
0
ファイル: eolcheck.c プロジェクト: bobrippling/cbin
static void checkfile(char *fname)
{
	struct stat st;

	if(lstat(fname, &st) != 0)
		fputs(strerror(errno), stdout);
	else if(S_ISDIR(st.st_mode))
		fputs("dir", stdout);
	else{
		FILE *f = fopen(fname, "r");

		if(!f || fseek(f, 0, SEEK_END)){
			fputs(strerror(errno), stdout);
		}else{
			/* now at eof */
			long pos = ftell(f);

			if(pos > 0){
				if(fseek(f, pos - 1, SEEK_SET))
					fputs(strerror(errno), stdout);
				else{
					if(fgetc(f) == '\n')
						fputs("eol", stdout);
					else{
						if(append){
							int add;
							if(prompt){
								printf("	\"%s\" - append newline? (Y/n) ", fname);
								add = yesno();
							}else
								add = 1;

							if(add){
								fclose(f);
								f = fopen(fname, "a");
								if(f){
									if(fputc('\n', f) == EOF)
										printf("append: %s", strerror(errno));
									else
										fputs("eol (added)", stdout);
									/* file closed below */
								}else
									fprintf(stderr, "open: %s", strerror(errno));
							}else
								fputs("noeol", stdout);
						}else
							fputs("noeol", stdout);
					}
				}
			}else
				fputs("zero length", stdout);
		}

		if(f)
			fclose(f);
	}

	printf(" - %s\n", fname);
}
コード例 #28
0
static void BuildCount()//PROBLEM 1 and 2
{
	int boolean = 1;
	int content;
	int length = 0;
	struct node *head = NULL;

	while(boolean)
	{
		if(yesno("Would you like to enter a value (Y/N)?"))
		{
			read_int("Please enter your value: ", &content);
			Append(&head, content);
		}
		else
		{
			boolean = 0;
		}
	}

	length = getLength(head);
	printf("The lenght of the tree is %d.\n", length);
	boolean = 1; //reset boolean to default to prepare for next while loop

	while(boolean)
	{
		int count = 0;
		if(yesno("Do you want to search for the total number of entries for a value (Y/N)?"))
		{
			read_int("Please enter your value to search for: ", &content);
			length = getLength(head);
			printf("The lenght of the tree is %d.\n", length);
			ElementSearch(head, content, &count);
			printf("The total number of entries for %d is %d.\n", content, count);
		}
		else
		{
			boolean = 0;
		}
	}
	freeElements(&head);//free up the allocated memory
	if(head == NULL)
	{
		printf("The head node was set to NULL.\n");
	}
}//END PROBLEM 1 and 2
コード例 #29
0
ファイル: friends.c プロジェクト: cafuego/monolith
static void
menu_friend_quick_add()
{

    char command;
    char *name;
    char old[L_USERNAME + 1];
    friend_t f;
    int i;
    unsigned int id2;

    nox = 1;
    menu_friend_list(FRIEND);

    cprintf("\1gWhich slot do you want to edit\1w: \1c");
    command = get_single("0123456789 \r\n");

    if (command == '\r' || command == ' ' || command == '\n' || command == 'q')
	return;

    i = command - '0';
    if (mono_sql_uu_quickx2user(usersupp->usernum, i, &id2) == -1) {
	strcpy(old, "");
    } else if (mono_cached_sql_u_id2name(id2, old) == -1) {
	strcpy(old, "");
    }
    if (strlen(old) != 0) {
	cprintf("\1gDo you want to remove \1y%s \1gfrom slot \1w(\1g%d\1w)\1g ?\1c ", old, i);
	if (yesno() == NO)
	    return;
	mono_sql_uu_remove_quickx(usersupp->usernum, id2);
    }
    /* ask new name! */

    cprintf("\1f\1gEnter username\1w: \1c");
    name = get_name(5);

    if (strlen(name) == 0)
	return;

    if (strchr(name, '@') != NULL) {
	cprintf("\1f\1rSorry, InterBBS names are not allowed.\n");
	return;
    } else if (mono_cached_sql_u_name2id(name, &id2) == -1) {
	cprintf("\1f\1rNo such user.\n");
	return;
    }
    if (!is_cached_friend(name)) {
	strcpy(f.name, name);
	f.quickx = i;
	mono_sql_uu_add_entry(usersupp->usernum, id2, L_FRIEND);
    } else
	mono_sql_uu_add_quickx(usersupp->usernum, id2, i);

    cprintf("\1f\1gUser \1y%s \1gwas added to slot \1w(\1g%d\1w)\1g.\n", name, i);

    return;
}
コード例 #30
0
ファイル: delete.c プロジェクト: alhazred/onarm
static KMF_RETURN
pk_delete_keys(KMF_HANDLE_T kmfhandle, KMF_ATTRIBUTE *attlist, int numattr,
	char *desc, int *keysdeleted)
{
	KMF_RETURN rv = KMF_OK;
	uint32_t numkeys = 0;
	int num = numattr;

	*keysdeleted = 0;
	numkeys = 0;

	kmf_set_attr_at_index(attlist, num,
	    KMF_COUNT_ATTR, &numkeys, sizeof (uint32_t));
	num++;

	rv = kmf_find_key(kmfhandle, num, attlist);

	if (rv == KMF_OK && numkeys > 0) {
		KMF_KEY_HANDLE *keys = NULL;
		char prompt[1024];

		(void) snprintf(prompt, sizeof (prompt),
		    gettext("%d %s key(s) found, do you want "
		    "to delete them (y/N) ?"), numkeys,
		    (desc != NULL ? desc : ""));

		if (!yesno(prompt,
		    gettext("Respond with yes or no.\n"),
		    B_FALSE)) {
			*keysdeleted = numkeys;
			return (KMF_OK);
		}
		keys = (KMF_KEY_HANDLE *)malloc(numkeys *
		    sizeof (KMF_KEY_HANDLE));
		if (keys == NULL)
			return (KMF_ERR_MEMORY);
		(void) memset(keys, 0, numkeys *
		    sizeof (KMF_KEY_HANDLE));

		kmf_set_attr_at_index(attlist, num,
		    KMF_KEY_HANDLE_ATTR, keys, sizeof (KMF_KEY_HANDLE));
		num++;

		rv = kmf_find_key(kmfhandle, num, attlist);
		if (rv == KMF_OK) {
			rv = pk_destroy_keys(kmfhandle, attlist, num);
		}

		free(keys);
	}

	if (rv == KMF_ERR_KEY_NOT_FOUND) {
		rv = KMF_OK;
	}

	*keysdeleted = numkeys;
	return (rv);
}