static void rebuild_channels(newtComponent c)
{
	void *prev = NULL;
	struct ast_chan *chan;
	char tmpn[42];
	char tmp[256];
	int x=0;
	prev = newtListboxGetCurrent(c);
	newtListboxClear(c);
	chan = chans;
	while(chan) {
		snprintf(tmpn, sizeof(tmpn), "%s (%s)", chan->name, chan->callerid);
		if (strlen(chan->exten)) 
			snprintf(tmp, sizeof(tmp), "%-30s %8s -> %s@%s:%s", 
				tmpn, chan->state,
				chan->exten, chan->context, chan->priority);
		else
			snprintf(tmp, sizeof(tmp), "%-30s %8s",
				tmpn, chan->state);
		newtListboxAppendEntry(c, tmp, chan);
		x++;
		chan = chan->next;
	}
	if (!x)
		newtListboxAppendEntry(c, " << No Active Channels >> ", NULL);
	newtListboxSetCurrentByKey(c, prev);
}
Example #2
0
static newtComponent
nmt_newt_listbox_build_component (NmtNewtComponent *component,
                                  gboolean          sensitive)
{
	NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (component);
	newtComponent co;
	int i, active;

	if (priv->active == -1)
		update_active_internal (NMT_NEWT_LISTBOX (component), 0);
	active = priv->active;

	co = newtListbox (-1, -1, priv->height, convert_flags (priv->flags));
	newtComponentAddCallback (co, selection_changed_callback, component);

	for (i = 0; i < priv->entries->len; i++) {
		newtListboxAppendEntry (co, priv->entries->pdata[i], GUINT_TO_POINTER (i));
		if (active == -1 && priv->keys->pdata[i] == priv->active_key)
			active = i;
	}

	if (active != -1)
		newtListboxSetCurrent (co, active);

	return co;
}
// =======================================================
char *processHardDrive(char *cPtr, newtComponent editPartition)
{
  char *cOldPtr;
  int nMajor, nMinor, nBlocks;
  int nPartNum;
  char szDevice[128];
  char szFullDevice[128];
  char cFormat[1024];
  char szTemp[1024];
  char *szDeviceName;
  int nRes;
  QWORD qwSize;

  cOldPtr = cPtr;
  nPartNum = 1;

  showDebug(9, "decode HD\n");

  while (*(cPtr) && *(cPtr+1) && *(cPtr+2) && nPartNum)
    {
      cPtr = decodePartitionEntry(cPtr, &nMajor, &nMinor, &nBlocks, &nPartNum, szDevice);
      if (nPartNum)
	{
	  cOldPtr = cPtr;

	  memset(cFormat, ' ', 50);
	  memset(cFormat+50, 0, 50);
	  
	  memcpy(cFormat, szDevice, strlen(szDevice)); // Device
	  
	  SNPRINTF(szFullDevice, "/dev/%s", szDevice);
	  checkInodeForDevice(szFullDevice);
	  
	  if (nBlocks > 1) // a standard device
	    {
	      nRes = detectFileSystem(szFullDevice, szTemp);
	      memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system
	      
	      qwSize = getPartitionSize(szFullDevice);
	      formatSize(qwSize, szTemp);	
	      memcpy(cFormat+50, szTemp, strlen(szTemp)); // Size
	    }
	  else if (nBlocks == 1) // an extended partition
	    {
	      SNPRINTF(szTemp, "-extended-");
	      memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system
	    }
	  
          szDeviceName = strdup(szFullDevice); // TOTO: never freed
	  newtListboxAppendEntry(editPartition, cFormat, (void*)szDeviceName);
          showDebug(9, "inserted[2]: %s\n", cFormat);
	  //debugWin("add[%s] and *cPtr=%d and 1=%d and 2=%d and 3=%d and 4=%d", cFormat, *(cPtr), *(cPtr+1), *(cPtr+2), *(cPtr+3), *(cPtr+4));
	}
    }

  return cOldPtr;
}
Example #4
0
static void add_cards(newtComponent spans)
{
	int x;
	char *s;
	void *prev=NULL;
	
	if (spans)
		prev = newtListboxGetCurrent(spans);
	newtListboxClear(spans);
	for (x=0;x<DAHDI_MAX_SPANS;x++) {
		s = getalarms(x, 0);
		if (s && spans) {
			/* Found one! */
			newtListboxAppendEntry(spans, s, (void *)(long)x);
		}
	}
	if (spans)
		newtListboxSetCurrentByKey(spans, prev);
	
}
/**
 * Pop up a list containing the filenames in @p source_file and the severity if they have changed since the
 * last backup. There can be no more than @p ARBITRARY_MAXIMUM files in @p source_file.
 * @param source_file The file containing a list of changed files.
 */
	void popup_changelist_from_file(char *source_file) {
		char *reason = NULL;
		newtComponent myForm;
		newtComponent bClose;
		newtComponent bSelect;
		newtComponent b_res;
		newtComponent fileListbox;
		newtComponent headerMsg;

		/*@ ???? ************************************************************ */
		void *curr_choice;
		void *keylist[ARBITRARY_MAXIMUM];

		/*@ int ************************************************************* */
		int i = 0;
		int currline = 0;
		int finished = FALSE;
		long lng = 0;

		/*@ buffers ********************************************************* */
		char *tmp;
		char *differ_sz;

		struct s_filelist *filelist;
		assert_string_is_neither_NULL_nor_zerolength(source_file);
		if (g_text_mode) {
			log_msg(2, "Text mode. Therefore, no popup list.");
			return;
		}
		log_msg(2, "Examining file %s", source_file);

		lng = count_lines_in_file(source_file);
		if (lng < 1) {
			log_msg(2, "No lines in file. Therefore, no popup list.");
			return;
		} else if (lng >= ARBITRARY_MAXIMUM) {
			log_msg(2, "Too many files differ for me to list.");
			return;
		}

		filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist));
		fileListbox =
			newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
		newtListboxClear(fileListbox);

		if (load_filelist_into_array(filelist, source_file)) {
			log_msg(2, "Can't open %s; therefore, cannot popup list",
					source_file);
			return;
		}
		log_msg(2, "%d files loaded into filelist array",
				filelist->entries);
		for (i = 0; i < filelist->entries; i++) {
			keylist[i] = (void *) i;
			newtListboxAppendEntry(fileListbox,
								   filelist_entry_to_string(&
															(filelist->
															 el[i])),
								   keylist[i]);
		}
		asprintf(&differ_sz,
				 _("  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list."),
				 i);
		newtPushHelpLine(differ_sz);
		paranoid_free(differ_sz);

		bClose = newtCompactButton(10, 15, _(" Close  "));
		bSelect = newtCompactButton(30, 15, _(" Select "));
		asprintf(&tmp, "%-10s               %-20s", _("Priority"),
				 _("Filename"));
		headerMsg = newtLabel(2, 1, tmp);
		paranoid_free(tmp);

		newtOpenWindow(5, 4, 70, 16, _("Non-matching files"));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
							  bSelect, NULL);
		while (!finished) {
			b_res = newtRunForm(myForm);
			if (b_res == bClose) {
				finished = TRUE;
			} else {
				curr_choice = newtListboxGetCurrent(fileListbox);
				for (i = 0;
					 i < filelist->entries && keylist[i] != curr_choice;
					 i++);
				if (i == filelist->entries && filelist->entries > 0) {
					log_to_screen(_("I don't know what that button does!"));
				} else {
					currline = i;
					if (filelist->entries > 0) {
						severity_of_difference(filelist->el[currline].
											   filename, reason);
						asprintf(&tmp, "%s --- %s",
								 filelist->el[currline].filename, reason);
						popup_and_OK(tmp);
						paranoid_free(tmp);
						paranoid_free(reason);
					}
				}
			}
		}
		newtFormDestroy(myForm);
		newtPopWindow();
		newtPopHelpLine();
	}
Example #6
0
/* Browse through a directory structure looking for a file.
 * Returns the full path to the file.
 *
 * Parameters:
 * title: Title for newt dialog window
 * dirname: Directory to use for root of browsing.  NOTE: you cannot go
 *          up above this root.
 * filterfunc: An (optional)  function to filter out files based on whatever
 *             criteria you want.  Returns 1 if it passes, 0 if not.
 *             Function should take arguments of the directory name and
 *             the dirent for the file.
 */
char * newt_select_file(char * title, char * text, char * dirname,
                        int (*filterfunc)(char *, struct dirent *)) {
    char ** files;
    char * fn = NULL;
    int i, done = 0;
    char * topdir = dirname;
    char * dir = malloc(PATH_MAX);
    char * path = NULL;
    newtGrid grid, buttons;
    newtComponent f, tb, listbox, ok, cancel;
    struct stat sb;
    struct newtExitStruct es;

    dir = realpath(dirname, dir);

    do {
        files = get_file_list(dir, filterfunc);

        f = newtForm(NULL, NULL, 0);
        grid = newtCreateGrid(1, 4);

        tb = newtTextboxReflowed(-1, -1, text, 60, 0, 10, 0);

        listbox = newtListbox(12, 65, 10,
                              NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);

        newtListboxSetWidth(listbox, 55);
        buttons = newtButtonBar(_("OK"), &ok, _("Cancel"), &cancel, NULL);
        newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, tb,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons,
                         0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

        /* if this isn't our topdir, we want to let them go up a dir */
        if (strcmp(topdir, dir))
            newtListboxAppendEntry(listbox, "../", "..");

        for (i = 0; (files[i] != NULL); i++) {
            if ((files[i] == NULL) || (strlen(files[i]) == 0)) continue;
            path = malloc(strlen(files[i]) + strlen(dir) + 2);
            sprintf(path, "%s/%s", dir, files[i]);
            stat(path, &sb);
            free(path);
            if (S_ISDIR(sb.st_mode)) {
                char *dir = malloc(strlen(files[i]) + 2);
                sprintf(dir, "%s/", files[i]);
                newtListboxAppendEntry(listbox, dir, files[i]);
            } else {
                newtListboxAppendEntry(listbox, files[i], files[i]);
            }
        }

        newtGridWrappedWindow(grid, title);
        newtGridAddComponentsToForm(grid, f, 1);
        newtFormRun(f, &es);

        if (es.reason  == NEWT_EXIT_COMPONENT && es.u.co == cancel) {
            fn = NULL;
            done = -1;
        } else {
            fn = (char *) newtListboxGetCurrent(listbox);
            path = malloc(strlen(fn) + strlen(dir) + 2);
            sprintf(path, "%s/%s", dir, fn);

            stat(path, &sb);
            if (!S_ISDIR(sb.st_mode)) {
                fn = path;
                done = 1;
            } else {
                dir = realpath(path, dir);
                free(path);
            }
        }

        newtGridFree(grid, 1);
        newtFormDestroy(f);
        newtPopWindow();
    } while (done == 0);

    return fn;
}
Example #7
0
static fde *dir_here(newtComponent lb, char *dr)
{
	struct dirent **namelist;
	int n, sz2, i;
	double sz1;
	char szb[20];
	char buf[128]; // really, we have newt listbox->width-7 (7 is for frame with listbox)
	time_t tt, ttt;
	struct tm *tmm;
	fde *dp, *dpp;
	
	tt=time(NULL);
	
	dp=(fde*)malloc(sizeof(fde));
	dp->name=dirname(strdup(dr));
	stat(dp->name,&dp->st);
	dpp=dp;
	newtListboxAppendEntry(lb, "..", dp);
	n = scandir(dr, &namelist, 0, alphasort);
	if(n < 0)
	{
		// TODO: replace with newt iface
		perror("scandir");
	} 
	else
	{
		for(i=0; i < n; i++)
		{
			if(strcmp(namelist[i]->d_name,".") != 0 &&strcmp(namelist[i]->d_name,"..") != 0)
			{
				dp=(fde*)malloc(sizeof(fde));
				dp->name=(char*)malloc(strlen(dr)+2+strlen(namelist[i]->d_name));
				strcpy(dp->name,dr);  
				if(strlen(dr) > 1) strcat(dp->name,"/"); strcat(dp->name,namelist[i]->d_name);
				stat(dp->name,&dp->st);
				tmm=localtime(&dp->st.st_mtime);
				ttt=tt-dp->st.st_mtime;
				if(dp->st.st_size >= 1024*1024*1024) // GiB: 999.99
				{
					sz1=(double)dp->st.st_size/1024.0/1024.0/1024.0;
					sprintf(szb,i18n("%6.2f GiB"),sz1);
				}
				else if(dp->st.st_size >= 1024*1024) // MiB: 999.99
				{
					sz1=(float)dp->st.st_size/1024.0/1024.0;
					sprintf(szb,i18n("%6.2f MiB"),sz1);
				}
				else // standard
				{
					sz2=dp->st.st_size; // avoid warnings
					sprintf(szb,i18n("%7d Bytes"),sz2);
				}
				
				sprintf(buf," %.30s %.40s",namelist[i]->d_name,"                                                                  ");
				if(ttt < 60*66*30*365) // current year
				sprintf(buf+31," |%s| %s %02d %02d:%02d",szb, months[tmm->tm_mon],tmm->tm_mday,tmm->tm_hour,tmm->tm_min);
				else 
				sprintf(buf+31," |%s| %s %02d %02d",szb,months[tmm->tm_mon], tmm->tm_mday,1900+tmm->tm_year);
				
				if(S_ISDIR(dp->st.st_mode))
				{
					buf[0]='/';
					newtListboxInsertEntry(lb, buf, dp,dpp);
					dpp=dp;
				}
				else
				{
					newtListboxAppendEntry(lb, buf, dp);
				}
			}
			free(namelist[i]);
		}
		free(namelist);
	}
	
	return dp;
}
Example #8
0
/* setup hard drive based install from a partition with a filesystem and
 * ISO images on that filesystem
 */
char * mountHardDrive(struct installMethod * method,
		      char * location, struct loaderData_s * loaderData) {
    int rc;
    int i;

    newtComponent listbox, label, dirEntry, form, okay, back, text;
    struct newtExitStruct es;
    newtGrid entryGrid, grid, buttons;

    int done = 0;
    char * dir = strdup("");
    char * tmpDir;
    char * url = NULL;
    char * buf, *substr;
    int numPartitions;

    char **partition_list;
    char *selpart;
    char *kspartition = NULL, *ksdirectory = NULL;

    /* handle kickstart/stage2= data first if available */
    if (loaderData->method == METHOD_HD && loaderData->stage2Data) {
        kspartition = ((struct hdInstallData *)loaderData->stage2Data)->partition;
        ksdirectory = ((struct hdInstallData *)loaderData->stage2Data)->directory;
        logMessage(INFO, "partition is %s, dir is %s", kspartition, ksdirectory);

        /* if exist, duplicate */
        if (kspartition)
            kspartition = strdup(kspartition);
        if (ksdirectory) {
            ksdirectory = strdup(ksdirectory);
        } else {
            ksdirectory = strdup("/images/install.img");
        }

        if (!kspartition || !ksdirectory) {
            logMessage(ERROR, "missing partition or directory specification");
            loaderData->method = -1;

            if (loaderData->inferredStage2)
                loaderData->invalidRepoParam = 1;
        } else {
            /* if we start with /dev, strip it (#121486) */
            char *kspart = kspartition;
            if (!strncmp(kspart, "/dev/", 5))
                kspart = kspart + 5;

            url = setupIsoImages(kspart, ksdirectory, location);
            if (!url) {
                logMessage(ERROR, "unable to find %s installation images on hd",
                           getProductName());
                loaderData->method = -1;

                if (loaderData->inferredStage2)
                    loaderData->invalidRepoParam = 1;
            } else {
                free(kspartition);
                free(ksdirectory);
                return url;
            }
        }
    } else {
        kspartition = NULL;
        ksdirectory = NULL;
    }

    /* if we're here its either because this is interactive, or the */
    /* hd kickstart directive was faulty and we have to prompt for  */
    /* location of harddrive image                                  */

    partition_list = NULL;
    while (!done) {
        /* if we're doing another pass free this up first */
        if (partition_list)
            freePartitionsList(partition_list);

        partition_list = getPartitionsList(NULL);
        numPartitions = lenPartitionsList(partition_list);

        /* no partitions found, try to load a device driver disk for storage */
        if (!numPartitions) {
            rc = newtWinChoice(_("Hard Drives"), _("Yes"), _("Back"),
                               _("You don't seem to have any hard drives on "
                                 "your system! Would you like to configure "
                                 "additional devices?"));
            if (rc == 2) {
                loaderData->stage2Data = NULL;
                return NULL;
            }

            rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0);
            continue;
        }

        /* now find out which partition has the stage2 image */
        checked_asprintf(&buf, _("What partition and directory on that "
                                 "partition holds the installation image "
                                 "for %s?  If you don't see the disk drive "
                                 "you're using listed here, press F2 to "
                                 "configure additional devices."),
                         getProductName());

        text = newtTextboxReflowed(-1, -1, buf, 62, 5, 5, 0);
        free(buf);

        listbox = newtListbox(-1, -1, numPartitions > 5 ? 5 : numPartitions,
                              NEWT_FLAG_RETURNEXIT | 
                              (numPartitions > 5 ? NEWT_FLAG_SCROLL : 0));

        for (i = 0; i < numPartitions; i++)
            newtListboxAppendEntry(listbox,partition_list[i],partition_list[i]);

        /* if we had ks data around use it to prime entry, then get rid of it*/
        if (kspartition) {
            newtListboxSetCurrentByKey(listbox, kspartition);
            free(kspartition);
            kspartition = NULL;
        }

        label = newtLabel(-1, -1, _("Directory holding image:"));

        dirEntry = newtEntry(28, 11, dir, 28, (const char **) &tmpDir,
                             NEWT_ENTRY_SCROLL);

        /* if we had ks data around use it to prime entry, then get rid of it*/
        if (ksdirectory) {
            newtEntrySet(dirEntry, ksdirectory, 1);
            free(ksdirectory);
            ksdirectory = NULL;
        }

        entryGrid = newtGridHStacked(NEWT_GRID_COMPONENT, label,
                                     NEWT_GRID_COMPONENT, dirEntry,
                                     NEWT_GRID_EMPTY);

        buttons = newtButtonBar(_("OK"), &okay, _("Back"), &back, NULL);

        grid = newtCreateGrid(1, 4);
        newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, entryGrid,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons,
                         0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

        newtGridWrappedWindow(grid, _("Select Partition"));

        form = newtForm(NULL, NULL, 0);
        newtFormAddHotKey(form, NEWT_KEY_F2);
        newtFormAddHotKey(form, NEWT_KEY_F12);

        newtGridAddComponentsToForm(grid, form, 1);
        newtGridFree(grid, 1);

        newtFormRun(form, &es);

        selpart = newtListboxGetCurrent(listbox);

        free(dir);
        if (tmpDir && *tmpDir) {
            /* Protect from form free. */
            dir = strdup(tmpDir);
        } else  {
            dir = strdup("");
        }

        newtFormDestroy(form);
        newtPopWindow();

        if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == back) {
            loaderData->stage2Data = NULL;
            return NULL;
        } else if (es.reason == NEWT_EXIT_HOTKEY && es.u.key == NEWT_KEY_F2) {
            rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0);
            continue;
        }

        logMessage(INFO, "partition %s selected", selpart);

        /* If the user-provided URL points at a repo instead of a stage2
         * image, fix that up now.
         */
        substr = strstr(dir, ".img");
        if (!substr || (substr && *(substr+4) != '\0')) {
            checked_asprintf(&dir, "%s/images/install.img", dir);
        }

        loaderData->invalidRepoParam = 1;

        url = setupIsoImages(selpart, dir, location);
        if (!url) {
            newtWinMessage(_("Error"), _("OK"), 
                           _("Device %s does not appear to contain "
                             "an installation image."), selpart, getProductName());
            continue;
        }

        done = 1; 
    }

    free(dir);

    return url;
}
int main(void) {
    newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
    newtComponent lb, t, rsf, answer, timeLabel;
    newtComponent cs[10];
    newtComponent f, chklist, e1;
    struct callbackInfo cbis[3];
    char results[10];
    char * enr2, * enr3, * scaleVal;
    void ** selectedList;
    int i, numsel;
    char buf[20];
    const char * spinner = "-\\|/\\|/";
    const char * spinState;
    struct newtExitStruct es;

    newtInit();
    newtCls();

    newtSetSuspendCallback(suspend, NULL);
    newtSetHelpCallback(helpCallback);

    newtDrawRootText(0, 0, "Newt test program");
    newtPushHelpLine(NULL);
    newtDrawRootText(-50, 0, "More root text");

    newtOpenWindow(2, 2, 30, 10, "first window");
    newtOpenWindow(10, 5, 65, 16, "window 2");

    f = newtForm(NULL, "This is some help text", 0);
    chklist = newtForm(NULL, NULL, 0);

    b1 = newtButton(3, 1, "Exit");
    b2 = newtButton(18, 1, "Update");
    r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL);
    r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1);
    r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2);
    rsf = newtForm(NULL, NULL, 0);
    newtFormAddComponents(rsf, r1, r2, r3, NULL);
    newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);

    for (i = 0; i < 10; i++) {
	sprintf(buf, "Check %d", i);
	cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
	newtFormAddComponent(chklist, cs[i]);
    }

    l1 = newtLabel(3, 6, "Scale:");
    l2 = newtLabel(3, 7, "Scrolls:");
    l3 = newtLabel(3, 8, "Hidden:");
    e1 = newtEntry(12, 6, "", 20, &scaleVal, 0);
    e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL);
/*    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */
    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD);

    cbis[0].state = &results[0];
    cbis[0].en = e1;
    newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);

    scale = newtScale(3, 14, 32, 100);

    newtFormSetHeight(chklist, 3);

    newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
    newtFormAddComponents(f, rsf, scale, NULL);

    lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
				NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
    newtListboxAppendEntry(lb, "First", (void *) 1);
    newtListboxAppendEntry(lb, "Second", (void *) 2);
    newtListboxAppendEntry(lb, "Third", (void *) 3);
    newtListboxAppendEntry(lb, "Fourth", (void *) 4);
    newtListboxAppendEntry(lb, "Sixth", (void *) 6);
    newtListboxAppendEntry(lb, "Seventh", (void *) 7);
    newtListboxAppendEntry(lb, "Eighth", (void *) 8);
    newtListboxAppendEntry(lb, "Ninth", (void *) 9);
    newtListboxAppendEntry(lb, "Tenth", (void *) 10);

    newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4);
    newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
    newtListboxDeleteEntry(lb, (void *) 11);

    spinState = spinner;
    timeLabel = newtLabel(45, 8, "Spinner: -");

    t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");

    newtFormAddComponents(f, lb, timeLabel, t, NULL);
    newtRefresh();
    newtFormSetTimer(f, 200);

    do {
	newtFormRun(f, &es);

	if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
	    newtScaleSet(scale, atoi(scaleVal));
	    newtRefresh();
	    answer = NULL;
	} else if (es.reason == NEWT_EXIT_TIMER) {
	    spinState++;
	    if (!*spinState) spinState = spinner;
	    sprintf(buf, "Spinner: %c", *spinState);
	    newtLabelSetText(timeLabel, buf);
	}
    } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2);

    scaleVal = strdup(scaleVal);
    enr2 = strdup(enr2);
    enr3 = strdup(enr3);

    selectedList = newtListboxGetSelection(lb, &numsel);

    newtFormDestroy(f);

    newtPopWindow();
    newtPopWindow();
    newtFinished();

    printf("got string 1: %s\n", scaleVal);
    printf("got string 2: %s\n", enr2);
    printf("got string 3: %s\n", enr3);

    if(selectedList) {
	printf("\nSelected listbox items:\n");
	for(i = 0; i < numsel; i++)
	    puts(selectedList[i]);
    }

    return 0;
}
// =======================================================
void CRestoreMbrWindow::addMbr(char *szText, DWORD dwNumber)
{
  BEGIN;
  newtListboxAppendEntry(m_list2, szText, (void*)dwNumber);
  RETURN;
}
// =======================================================
int fillPartitionList(newtComponent editPartition)
{
  BEGIN;

  FILE *fPart;
  int nMajor, nMinor, nBlocks;
  char szDevice[128];
  char szFullDevice[128];
  char cBuffer[32768];
  char cFormat[1024];
  char szTemp[1024];
  char *cPtr;
  int nLines;
  unsigned int nSize;
  QWORD qwSize;
  int i;
  int nRes;
  char *szDeviceName;
  int nPartNum;
  
  errno = 0;
  fPart = fopen("/proc/partitions", "rb");
  if (!fPart)
    {	
      g_interface->msgBoxError(i18n("Cannot read \"/proc/partitions\" (%s). Then, you must use the "
				    "command line to run Partition Image. Type \"partimage --help\" for help."), strerror(errno));
      RETURN_int(-1);	
    }
  
  nSize = 0;
  nLines = 0;
  memset(cBuffer, 0, sizeof(cBuffer));
  showDebug(9, "Reading /proc/partitions file\n");
  while (nSize < sizeof(cBuffer) && !feof(fPart))
    {
      nRes = fgetc(fPart);
      if (nRes != -1)
        cBuffer[nSize] = nRes;
      else
        showDebug(9, "error in fgetc\n");
      if (cBuffer[nSize] == '\n')
        {
	  ++nLines;
          showDebug(9, "%d lines read\n", nLines);
        }
      ++nSize;
    }
  if (nSize < sizeof(cBuffer)) 
    cBuffer[nSize] = '\0';
  else
    cBuffer[sizeof(cBuffer)-1] = '\0';

  fclose(fPart);
  showDebug(9, "/proc/partitions read -> \n%s\n", cBuffer);
  
  cPtr = cBuffer;
  
  // skip two first lines
  nLines -= 2;
  for (i=0; i < 2; i++)
    {
      while (*cPtr != '\n')
	cPtr++;
      cPtr++;
    }
  
  while (*(cPtr) && *(cPtr+1)&& *(cPtr+2))
  //for (i=0; i < nLines; i++) // TO BE CHANGED
    {
      cPtr = decodePartitionEntry(cPtr, &nMajor, &nMinor, &nBlocks, &nPartNum, szDevice);
      
      // detect file system of the hard disk
      SNPRINTF(szFullDevice, "/dev/%s", szDevice);
      checkInodeForDevice(szFullDevice);
      nRes = detectFileSystem(szFullDevice, szTemp);

      showDebug(9, "device %s\n", szDevice);     
 
      if (nRes != -1) // if a removable media
	{
          showDebug(9, "removable media found: %s\n", szTemp);
	  // add media
	  memset(cFormat, ' ', 50);
	  memset(cFormat+50, 0, 50);
	  
	  memcpy(cFormat, szDevice, strlen(szDevice)); // Device

	  memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system
	  
	  qwSize = getPartitionSize(szFullDevice);
	  formatSize(qwSize, szTemp);	
	  memcpy(cFormat+50, szTemp, strlen(szTemp)); // Size

          szDeviceName = strdup(szFullDevice); // TODO: never freed
	  newtListboxAppendEntry(editPartition, cFormat, (void*)szDeviceName);
          showDebug(9, "inserted: %s\n", cFormat);

	  // skip partitions
	  cPtr = skipPartitionsEntries(cPtr);
	}
      else // if an hard disk
	{
	  cPtr = processHardDrive(cPtr, editPartition);
	}
    }

  RETURN_int(0);
}