void Process_Save( void ) { static char *untitledStr = NULL; static char newName[MAX_FNAME]; char *tmp1 = NULL; char *tmp2 = NULL; int c; DialogFlag = SAVE; fileIOMode = FILE_WRITE; untitledStr = GETSTR(2,20, "UNTITLED"); tmp1= strrchr(last_fname, '/'); if (tmp1) { c = tmp1[1]; tmp2 = strchr(tmp1, c); strcpy(newName, tmp2); } if (strncmp(newName, untitledStr, 8) == 0 || last_fname[0] == NULL) Process_SaveAs(); else { if (SavedOnce == True) { if (!Write_File(last_fname)) DoErrorDialog( GETSTR(16,4, "Unable to write data to file") ); else Dirty = False; } else Process_SaveAs(); } }
bool CReBar::OnCreate(CREATESTRUCT *pCS) { if (!m_btnTools.Create<CToolBarButton>(m_hWnd, ID_TOOLS, &m_mdcToolsBtn, NULL, true, (HMENU)BUTTON_ID_TOOLS)) ASSERTRETURN(false); if (!m_btnSeen.Create<CToolBarButton>(m_hWnd, ID_SEEN, &m_mdcSeenBtn, NULL, false, (HMENU)BUTTON_ID_SEENMAIN)) ASSERTRETURN(false); if (!m_btnSort.Create<CToolBarButton>(m_hWnd, ID_SORT, &m_mdcSortBtn, NULL, true, (HMENU)BUTTON_ID_SORT)) ASSERTRETURN(false); if (!m_btnView.Create<CToolBarButton>(m_hWnd, ID_VIEW, &m_mdcViewBtn, NULL, false, (HMENU)BUTTON_ID_VIEW)) ASSERTRETURN(false); if (!m_eSearch.Create<RHintEdit>(m_hWnd, ES_AUTOHSCROLL, 0, NULL, 0, 0, 0, 0, ID_SEARCH)) ASSERTRETURN(false); if (!m_categoryBar.Create<CCategoryBar>(m_hWnd)) ASSERTRETURN(false); // Create tooltip windows for buttons HINSTANCE hInst = GetModuleHandle(NULL); CreateToolTip(m_hWnd, BUTTON_ID_TOOLS, hInst, GETSTR(IDS_TOOLTIP_TOOLS)); CreateToolTip(m_hWnd, BUTTON_ID_SEENMAIN, hInst, GETSTR(IDS_TOOLTIP_SEENMAIN)); CreateToolTip(m_hWnd, BUTTON_ID_SORT, hInst, GETSTR(IDS_TOOLTIP_SORT)); CreateToolTip(m_hWnd, BUTTON_ID_VIEW, hInst, GETSTR(IDS_TOOLTIP_VIEW)); m_mdc.Create(0, 0); OnPrefChanged(); return true; }
String Forwarder::Forward::getBody(int cnt, Message *msg) { Date64 date(msg->time); Format format; format.addVar("msgFrom", !strlen(GETCNTC(cnt, CNT_DISPLAY)) ? msg->fromUid : GETCNTC(cnt, CNT_DISPLAY)); format.addVar("msgTime", date.strftime(GETSTR(cfg::timeFormat))); format.addVar("msgDate", Helpers::isToday(date) ? "" : date.strftime(GETSTR(cfg::dateFormat))); format.addVar("msgBody", msg->body); return format.parse(GETSTR(this->parent->cfgCols["tplForward"])); }
void Process_Resize( void ) { int flag; char old_width[10], old_height[10]; static char *untitledStr = NULL; if ( DialogFlag == NEW ) { strcpy(undo_file, last_fname); last_fname[0] = '\0'; SavedOnce = False; Backup_Icons(); /* for undo */ flag = DO_NOT_SAVE; Init_Icons(icon_width, icon_height, flag); if (!untitledStr) untitledStr = GETSTR(2,20, "UNTITLED"); strcpy(last_fname, untitledStr); strcat(last_fname, ".m.pm"); last_fname[strlen(last_fname)] = '\0'; ChangeTitle(); Repaint_Exposed_Tablet(); Dirty = False; NewFlag = TRUE; } else{ sprintf(old_width, "%d", icon_width); XmTextFieldSetString(newWidthText, old_width); sprintf(old_height, "%d", icon_height); XmTextFieldSetString(newHeightText, old_height); XtManageChild(newIconDialog); XmProcessTraversal(newWidthText, XmTRAVERSE_CURRENT); XmTextFieldSetSelection(newWidthText, 0, 3, CurrentTime); } }
static symbol_t * find_tag (ty_meta_e meta, symbol_t *tag, type_t *type) { const char *tag_name; symbol_t *sym; if (tag) { tag_name = va ("tag %s", tag->name); } else { const char *path = GETSTR (pr.source_file); const char *file = strrchr (path, '/'); if (!file++) file = path; tag_name = va ("tag .%s.%d", file, pr.source_line); } sym = symtab_lookup (current_symtab, tag_name); if (sym) { if (sym->table == current_symtab && sym->type->meta != meta) error (0, "%s defined as wrong kind of tag", tag->name); if (sym->type->meta == meta) return sym; } sym = new_symbol (tag_name); if (!type) type = new_type (); if (!type->name) type->name = sym->name; sym->type = type; sym->type->type = ev_invalid; sym->type->meta = meta; sym->sy_type = sy_type; return sym; }
static void Do_DropCheckOp( DtDndTransferCallback transferInfo) { #ifdef DEBUG if (debug) { stat_out(" Doing DROP OPERATION :\n"); stat_out(" name is = %s\n", dropFileName); } #endif if (dropFileName[0] != '\0') { if (!Read_File(dropFileName)) { DoErrorDialog( GETSTR(16,2, "The file cannot be accessed\nor contains invalid data") ); transferInfo->status = DtDND_FAILURE; } else { transferInfo->status = DtDND_SUCCESS; } /* else */ } /* if */ }
void Eval_NewSize( int width, int height ) { char old_width[10], old_height[10]; int flag; if ((width < 1) || (width > xrdb.maxIconWidth) || (height < 1) || (height > xrdb.maxIconHeight)) { sprintf(old_width, "%d", icon_width); XmTextFieldSetString(newWidthText, old_width); sprintf(old_height, "%d", icon_height); XmTextFieldSetString(newHeightText, old_height); DoErrorDialog(GETSTR(16,10,"Invalid width and/or\nheight specified")); } else { if (DialogFlag == NEW) flag = DO_NOT_SAVE; else flag = DO_SAVE; Backup_Icons(); /* for undo */ Init_Icons(width, height, flag); } }
void Process_Undo( void ) { if (UndoFlag) { if ((icon_width != backup_width) || (icon_height != backup_height)) Init_Icons(backup_width, backup_height, DO_NOT_SAVE); XCopyArea(dpy, prev_color_icon, color_icon, Color_gc, 0, 0, icon_width, icon_height, 0, 0); XCopyArea(dpy, prev_mono_icon, mono_icon, Mono_gc, 0, 0, icon_width, icon_height, 0, 0); if (XtWindow(iconImage)) XCopyArea(dpy, color_icon, XtWindow(iconImage), Color_gc, 0, 0, icon_width, icon_height, 0, 0); if (XtWindow(monoImage)) XCopyArea(dpy, mono_icon, XtWindow(monoImage), Mono_gc, 0, 0, icon_width, icon_height, 0, 0); Repaint_Exposed_Tablet(); UndoFlag = False; Dirty = True; XtSetSensitive( editMenu_undo_pb, False); if ( NewFlag == TRUE ){ NewFlag = False; strcpy(last_fname, undo_file); last_fname[strlen(last_fname)] = '\0'; ChangeTitle();} } else DoErrorDialog( GETSTR(16,8,"There is no previous\nimage available") ); }
void Process_Quit( void ) { extern int ttMark; extern int tt_tmpfile_fd; DialogFlag = QUIT; if (Dirty) DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\nYour changes will be lost.") ); else { #ifdef __TOOLTALK edit_notifier(NULL, 0, 1); ttdt_session_quit( 0, 0, 1 ); ttdt_close( 0, 0, 1 ); tt_release( ttMark ); if (tt_tmpfile_fd != -1) { unlink(last_fname); if (fileFormat != FORMAT_XPM ) { unlink(dummy); } /* if */ } /* if */ #endif exit(0); } /* else */ }
static Widget build_stdErrDialog( void ) { Widget stdErrDialog_shell; XmString tmpXmStr, tmpXmStr2; Arg args[10]; int n; stdErrDialog_shell = XtVaCreatePopupShell( "stdErrDialog_shell", xmDialogShellWidgetClass, mainWindow, XmNtitle, GETSTR(8,2, "Icon Editor - Error"), NULL ); tmpXmStr = GETXMSTR(8,4, "Continue"); tmpXmStr2= GETXMSTR(8,2, "Icon Editor - Error"); stdErrDialog = XtVaCreateWidget( "stdErrDialog", xmMessageBoxWidgetClass, stdErrDialog_shell, XmNokLabelString, tmpXmStr, XmNdialogTitle, tmpXmStr2, XmNdialogType, XmDIALOG_ERROR, NULL ); XmStringFree(tmpXmStr); XmStringFree(tmpXmStr2); XtAddCallback( stdErrDialog, XmNokCallback, okCallback_stdErrDialog, NULL); n = 0; XtSetArg (args[n], XmNuseAsyncGeometry, True); n++; XtSetArg (args[n], XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++; XtSetValues (stdErrDialog_shell, args, n); return ( stdErrDialog ); }
void Process_GrabImage( void ) { DialogFlag = GRAB; if (Dirty) DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\nYour changes will be lost.") ); else Do_GrabOp(); }
String Forwarder::Summary::getBody() { Format format; format.addVar("msgCount", inttostr(this->receivedMsgCount)); format.addVar("userCount", inttostr(this->msgSenders.size())); format.addVar("lastMsgFrom", this->lastMsgFrom); format.addVar("userList", this->getMsgSendersList()); return format.parse(GETSTR(this->parent->cfgCols["tplSummary"])); }
/*************************************************************************** * * * Routine: Process_New * * * * Purpose: Process the selection of the NEW button in the 'File' * * pulldown menu. If the 'Dirty' flag is set, changes have * * been made to the drawing tablet since the last save, which * * would be lost by quitting. Notify the user of this and * * allow them the chance to change their minds. If they do * * not, pop-up the NewIconDialog for the user to select new * * dimensions (if desired) for the new icon. * * * ***************************************************************************/ void Process_New( void ) { DialogFlag = NEW; if (Dirty) DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\n\nYour changes will be lost.") ); else { Process_Resize(); DialogFlag = NONE; } }
void Process_FlipH( void ) { if (Selected) { Backup_Icons(); Mirror_Image(HORIZONTAL); } else DoErrorDialog( GETSTR(16,12, "No area has been selected") ); }
void CStatusBar::OnPrefChanged() { m_bBackgrWinDefault = GETTHEMEBOOL(_T("StatusBar"), _T("BackgrWindowsDefault")); m_clrBackgrT = GETTHEMECOLOR(_T("StatusBar"), _T("BackgrTopColor")); m_clrBackgrB = GETTHEMECOLOR(_T("StatusBar"), _T("BackgrBottomColor")); m_clrBackgrLine = GETTHEMECOLOR(_T("StatusBar"), _T("BackgrLineColor")); m_clrText = GETTHEMECOLOR(_T("StatusBar"), _T("TextColor")); SetText(GETSTR(IDS_READY)); OnScaleChanged(); }
void Process_Scale( void ) { if (Selected) { Backup_Icons(); Backup_G_Op = GraphicsOp; GraphicsOp = S_SCALE_1; FirstRigid = True; } else DoErrorDialog( GETSTR(16,12, "No area has been selected") ); }
void Process_DropOp( Widget w, XtPointer client_data, XtPointer call_data) { DialogFlag = DROP; if (Dirty) DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\n\nYour changes will be lost.") ); else { Do_DropOp();} }
void Process_Open( void ) { DialogFlag = OPEN; fileIOMode = FILE_READ; if (Dirty) DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\nYour changes will be lost.") ); else { XtManageChild(fileIODialog); SetFileIODialogInfo(); } }
void Iterate(void (*cb_uvod)(int), void (* cb_kniha)(int)) { int kniha, uvod; for (kniha = 3, uvod = 0; kniha < HDR.n_knihy || uvod < HDR.n_uvod; ) { if (uvod < HDR.n_uvod && (kniha >= HDR.n_knihy || uvod <= get_uvod_pre_knihu(GETSTR(KNIHA[kniha].meno)))) { cb_uvod(uvod); uvod++; } else { if (KNIHA[kniha].n_hlav > 0) { cb_kniha(kniha); } kniha++; } } }
void Process_Copy( XImage **img, XImage **img_mono ) { if (Selected) { *img = XGetImage(dpy, color_icon, select_box.x, select_box.y, select_box.width, select_box.height, AllPlanes, format); *img_mono = XGetImage(dpy, mono_icon, select_box.x, select_box.y, select_box.width, select_box.height, AllPlanes, format); XtSetSensitive( editMenu_paste_pb, True); } else DoErrorDialog( GETSTR(16,12, "No area has been selected") ); }
static Widget build_queryDialog( void ) { Widget queryDialog_shell; XmString tmpXmStr, tmpXmStr2, tmpXmStr3, tmpXmStr4, tmpXmStr5; Arg args[10]; int n; queryDialog_shell = XtVaCreatePopupShell( "queryDialog_shell", xmDialogShellWidgetClass, mainWindow, XmNtitle, GETSTR(6,2, "Icon Editor - Warning"), NULL ); tmpXmStr = GETXMSTR(6,2, "Icon Editor - Warning"); tmpXmStr2= GETXMSTR(6,6, "OK"); tmpXmStr3= GETXMSTR(6,8, "Do ya really wanna?"); tmpXmStr4= GETXMSTR(6,10, "Cancel"); tmpXmStr5= GETXMSTR(4,10, "Help"); queryDialog = XtVaCreateWidget( "queryDialog", xmMessageBoxWidgetClass, queryDialog_shell, XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON, XmNdialogTitle, tmpXmStr, XmNokLabelString, tmpXmStr2, XmNmessageString, tmpXmStr3, XmNcancelLabelString, tmpXmStr4, XmNhelpLabelString, tmpXmStr5, XmNdialogType, XmDIALOG_WARNING, NULL ); XmStringFree(tmpXmStr); XmStringFree(tmpXmStr2); XmStringFree(tmpXmStr3); XmStringFree(tmpXmStr4); XmStringFree(tmpXmStr5); XtAddCallback( queryDialog, XmNokCallback, okCallback_queryDialog, NULL); XtAddCallback( queryDialog, XmNcancelCallback, cancelCB_queryDialog, NULL); n = 0; XtSetArg (args[n], XmNuseAsyncGeometry, True); n++; XtSetArg (args[n], XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++; XtSetValues (queryDialog_shell, args, n); return ( queryDialog ); }
void Process_Paste( void ) { if (CutCopy) { Backup_Icons(); Backup_G_Op = GraphicsOp; GraphicsOp = S_PASTE; FirstRigid = True; /* grayout unusable stuff */ XtSetSensitive( editMenu_cut_pb, False); XtSetSensitive( editMenu_copy_pb, False); XtSetSensitive(editMenu_rotate_pb, False); XtSetSensitive(editMenu_flip_pb, False); XtSetSensitive(editMenu_scale_pb, False); XSync(dpy, 0); } else DoErrorDialog(GETSTR(16,14, "No area was previously\ncut or copied")); }
void cb_main_kniha(int kniha) { int comment; char *s; int h, v, id; char* meno = GETSTR(KNIHA[kniha].meno); printf("\n\n<a name=\"%s\">\n", meno); init_search(meno); add_search(1, 1, -1, -1); do_search(); h = 0; v = 0; while (get_result_id(&comment, &s, &id)) { if (!comment) { while (1) { // normalize h / v while (1) { if (h < 0 || h >= KNIHA[kniha].n_hlav) { h = -1; break; } else if (v >= GETPTR(hlava, KNIHA[kniha].hlava)[h].n_versov) { v = 0; h++; } else break; } if (h >= 0 && GETPTR(vers, (GETPTR(hlava, KNIHA[kniha].hlava)[h].vers))[v].min <= id) { printf("<a name=\"%s%d,%d\">\n", meno, h + 1, v + 1); v++; } else break; } TranslateLinksAndPrint(s); printf("\n"); } else { printf("<span id=\"e%d\" ", html_id); printf("class=\"komentar\">("); TranslateLinksAndPrint(s); printf(")</span>\n"); html_id++; } } }
void getTCstr(void) { char *ent; char *suc; char *pt = funcstr; int r; ent = getenv("TERM") ? getenv("TERM") : DEFAULT_TERM; if (ent == NULL) { fprintf(stderr, "TERM is not set\n"); reset_exit(SIGNAL_ARGLIST); } r = tgetent(bp, ent); if (r != 1) { /* Can't find termcap entry */ fprintf(stderr, "Can't find termcap entry %s\n", ent); reset_exit(SIGNAL_ARGLIST); } GETSTR(T_ce, "ce"); /* clear to the end of line */ GETSTR(T_cd, "cd"); /* clear to the end of display */ GETSTR(T_kr, "nd"); /* cursor right */ if (suc == NULL) GETSTR(T_kr, "kr"); if (tgetflag("bs")) T_kl = "\b"; /* cursor left */ else { GETSTR(T_kl, "le"); if (suc == NULL) GETSTR(T_kl, "kb"); if (suc == NULL) GETSTR(T_kl, "kl"); } GETSTR(T_cr, "cr"); /* carriage return */ GETSTR(T_ta, "ta"); /* tab */ GETSTR(T_sc, "sc"); /* save cursor */ GETSTR(T_rc, "rc"); /* restore cursor */ GETSTR(T_so, "so"); /* standout mode */ GETSTR(T_se, "se"); /* standout mode end */ GETSTR(T_us, "us"); /* underline mode */ GETSTR(T_ue, "ue"); /* underline mode end */ GETSTR(T_md, "md"); /* bold mode */ GETSTR(T_me, "me"); /* bold mode end */ GETSTR(T_cl, "cl"); /* clear screen */ GETSTR(T_cm, "cm"); /* cursor move */ GETSTR(T_al, "al"); /* append line */ GETSTR(T_sr, "sr"); /* scroll reverse */ GETSTR(T_ti, "ti"); /* terminal init */ GETSTR(T_te, "te"); /* terminal end */ GETSTR(T_nd, "nd"); /* move right one space */ GETSTR(T_eA, "eA"); /* enable alternative charset */ GETSTR(T_as, "as"); /* alternative (graphic) charset start */ GETSTR(T_ae, "ae"); /* alternative (graphic) charset end */ GETSTR(T_ac, "ac"); /* graphics charset pairs */ GETSTR(T_op, "op"); /* set default color pair to its original value */ #if defined( CYGWIN ) && CYGWIN < 1 /* for TERM=pcansi on MS-DOS prompt. */ #if 0 T_eA = ""; T_as = "\033[12m"; T_ae = "\033[10m"; T_ac = "l\001k\002m\003j\004x\005q\006n\020a\024v\025w\026u\027t\031"; #endif T_eA = ""; T_as = ""; T_ae = ""; T_ac = ""; #endif /* CYGWIN */ LINES = COLS = 0; setlinescols(); setgraphchar(); }
void *htext_get_method(void *h) { htext_handle *handle = (htext_handle*)h; CURL *curl; htext_partial *partial_array, head; size_t unused, fsize, stream_size, last_size; char err_buffer[CURL_ERROR_SIZE]; void *f; int i, npartials; /* Create the file */ f = GETIO(handle)->open(GETSTR(handle, HTEXTOP_DESTINATIONURL), "w", GETPTR(handle, HTEXTOP_IO_HANDLER_DATA)); if (!f) { handle->status = HTEXTS_FAILED; strerror_r(errno, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); return NULL; } GETIO(handle)->close(f); /* Create and initialize CURL handle with common stuff */ curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_buffer); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, htext_header_callback); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_URL, GETSTR(handle, HTEXTOP_SOURCEURL)); curl_easy_setopt(curl, CURLOPT_USERAGENT, GETSTR(handle, HTEXTOP_CLIENTID)); curl_easy_setopt(curl, CURLOPT_CAPATH, GETSTR(handle, HTEXTOP_CAPATH)); curl_easy_setopt(curl, CURLOPT_CAINFO, GETSTR(handle, HTEXTOP_CAFILE)); curl_easy_setopt(curl, CURLOPT_SSLCERT, GETSTR(handle, HTEXTOP_USERCERTIFICATE)); curl_easy_setopt(curl, CURLOPT_SSLKEY, GETSTR(handle, HTEXTOP_USERPRIVKEY)); curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, GETSTR(handle, HTEXTOP_USERPRIVKEYPASS)); curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST, htext_cipher_suite()); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); if (GETINT(handle, HTEXTOP_VERBOSITY) > 1) { curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, htext_debug_callback); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } if (GETINT(handle, HTEXTOP_BUFFERSIZE) > 0) { curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, GETINT(handle, HTEXTOP_BUFFERSIZE)); } /* Shared */ curl_easy_setopt(curl, CURLOPT_SHARE, handle->curl_share); /* Do a HEAD to get the size */ htext_partial_init(&head); fsize = 0; head.partial_total = &fsize; head.partial_done = &unused; curl_easy_setopt(curl, CURLOPT_NOBODY, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_HEADERDATA, &head); handle->status = HTEXTS_WAITING; htext_log(handle, "Asking for the size"); if (curl_easy_perform(curl) != CURLE_OK) { htext_error(handle, err_buffer); } if (head.http_status >= 400 || handle->status == HTEXTS_FAILED) { handle->http_status = head.http_status; handle->status = HTEXTS_FAILED; htext_partial_clean(&head); curl_easy_cleanup(curl); return NULL; } /* Did we get the location, and is it cacheable? */ if (head.location && head.redirect_is_cacheable) { curl_easy_setopt(curl, CURLOPT_URL, head.location); } /* Calculate stream size and final stream size */ if (fsize) { npartials = GETINT(handle, HTEXTOP_NUMBEROFSTREAMS); if (fsize % npartials == 0) { stream_size = last_size = fsize / npartials; } else { stream_size = fsize / npartials; last_size = stream_size + (fsize % npartials); } } else { /* No size? Too bad, won't be able to stream */ npartials = 1; stream_size = last_size = 0; htext_log(handle, "No Content-Length, so no multistream possible"); } /* Set progress function */ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, htext_progress_callback); /* Set up partials */ handle->partial_total = calloc(sizeof(size_t), npartials); handle->partial_done = calloc(sizeof(size_t), npartials); handle->partials = npartials; /* Spawn a thread per partial */ htext_log(handle, "Downloading"); handle->status = HTEXTS_RUNNING; partial_array = calloc(sizeof(htext_partial), npartials); for (i = 0; i < npartials; ++i) { htext_partial_init(&(partial_array[i])); partial_array[i].index = i; partial_array[i].handle = handle; partial_array[i].curl = curl_easy_duphandle(curl); partial_array[i].partial_total = &(handle->partial_total[i]); partial_array[i].partial_done = &(handle->partial_done[i]); /* duphandle doesn't duplicate this :( */ curl_easy_setopt(partial_array[i].curl, CURLOPT_SHARE, handle->curl_share); /* Open */ partial_array[i].fd = GETIO(handle)->open(GETSTR(handle, HTEXTOP_DESTINATIONURL), "w", GETPTR(handle, HTEXTOP_IO_HANDLER_DATA)); if (!partial_array[i].fd) { handle->status = HTEXTS_FAILED; break; } /* Range and seek */ partial_array[i].start = i * stream_size; if (i < handle->partials - 1) partial_array[i].end = partial_array[i].start + stream_size - 1; else partial_array[i].end = partial_array[i].start + last_size - 1; *(partial_array[i].partial_total) = partial_array[i].end - partial_array[i].start; if (GETIO(handle)->seek(partial_array[i].fd, partial_array[i].start, SEEK_SET) < 0) { handle->status = HTEXTS_FAILED; break; } /* Launch */ pthread_create(&(partial_array[i].thread), NULL, htext_get_subthread, &(partial_array[i])); } /* Exited on error? */ if (handle->status == HTEXTS_FAILED) { strerror_r(errno, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); } /* Wait for all of them */ for (i = 0; i < npartials; ++i) { /* Wait, or kill if failed */ if (handle->status == HTEXTS_FAILED) pthread_cancel(partial_array[i].thread); pthread_join(partial_array[i].thread, NULL); if (handle->status != HTEXTS_FAILED) handle->http_status = partial_array[i].http_status; /* Clean partial */ htext_partial_clean(&(partial_array[i])); /* Check code */ if (handle->http_status < 200 || handle->http_status >= 300) { handle->status = HTEXTS_FAILED; } } /* Done */ if (handle->status == HTEXTS_RUNNING) { handle->status = HTEXTS_SUCCEEDED; } curl_easy_cleanup(curl); htext_partial_clean(&head); free(partial_array); return NULL; }
int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) { const unsigned char *p = message->options; const unsigned char *end = p; /* Add size later for gcc-3 issue */ unsigned char option; unsigned char length; unsigned int len = 0; int i; int retval = -1; route_t *routers = NULL; route_t *routersp = NULL; route_t *static_routes = NULL; route_t *static_routesp = NULL; route_t *csr = NULL; end += sizeof (message->options); dhcp->address.s_addr = message->yiaddr; strlcpy (dhcp->servername, message->servername, sizeof (dhcp->servername)); #define LEN_ERR \ { \ logger (LOG_ERR, "invalid length %d for option %d", length, option); \ p += length; \ continue; \ } while (p < end) { option = *p++; if (! option) continue; length = *p++; if (p + length >= end) { logger (LOG_ERR, "dhcp option exceeds message length"); retval = -1; goto eexit; } switch (option) { case DHCP_END: goto eexit; case DHCP_MESSAGETYPE: retval = (int) *p; p += length; continue; default: if (length == 0) { logger (LOG_DEBUG, "option %d has zero length, skipping", option); continue; } } #define LENGTH(_length) \ if (length != _length) \ LEN_ERR; #define MIN_LENGTH(_length) \ if (length < _length) \ LEN_ERR; #define MULT_LENGTH(_mult) \ if (length % _mult != 0) \ LEN_ERR; #define GET_UINT8(_val) \ LENGTH (sizeof (uint8_t)); \ memcpy (&_val, p, sizeof (uint8_t)); #define GET_UINT16(_val) \ LENGTH (sizeof (uint16_t)); \ memcpy (&_val, p, sizeof (uint16_t)); #define GET_UINT32(_val) \ LENGTH (sizeof (uint32_t)); \ memcpy (&_val, p, sizeof (uint32_t)); #define GET_UINT16_H(_val) \ GET_UINT16 (_val); \ _val = ntohs (_val); #define GET_UINT32_H(_val) \ GET_UINT32 (_val); \ _val = ntohl (_val); switch (option) { case DHCP_ADDRESS: GET_UINT32 (dhcp->address.s_addr); break; case DHCP_NETMASK: GET_UINT32 (dhcp->netmask.s_addr); break; case DHCP_BROADCAST: GET_UINT32 (dhcp->broadcast.s_addr); break; case DHCP_SERVERIDENTIFIER: GET_UINT32 (dhcp->serveraddress.s_addr); break; case DHCP_LEASETIME: GET_UINT32_H (dhcp->leasetime); break; case DHCP_RENEWALTIME: GET_UINT32_H (dhcp->renewaltime); break; case DHCP_REBINDTIME: GET_UINT32_H (dhcp->rebindtime); break; case DHCP_MTU: GET_UINT16_H (dhcp->mtu); /* Minimum legal mtu is 68 accoridng to RFC 2132. In practise it's 576 (minimum maximum message size) */ if (dhcp->mtu < MTU_MIN) { logger (LOG_DEBUG, "MTU %d is too low, minimum is %d; ignoring", dhcp->mtu, MTU_MIN); dhcp->mtu = 0; } break; #undef GET_UINT32_H #undef GET_UINT32 #undef GET_UINT16_H #undef GET_UINT16 #undef GET_UINT8 #define GETSTR(_var) \ MIN_LENGTH (sizeof (char)); \ if (_var) free (_var); \ _var = xmalloc (length + 1); \ memcpy (_var, p, length); \ memset (_var + length, 0, 1); case DHCP_HOSTNAME: GETSTR (dhcp->hostname); break; case DHCP_DNSDOMAIN: GETSTR (dhcp->dnsdomain); break; case DHCP_MESSAGE: GETSTR (dhcp->message); break; case DHCP_ROOTPATH: GETSTR (dhcp->rootpath); break; case DHCP_NISDOMAIN: GETSTR (dhcp->nisdomain); break; #undef GETSTR #define GETADDR(_var) \ MULT_LENGTH (4); \ if (! dhcp_add_address (&_var, p, length)) \ { \ retval = -1; \ goto eexit; \ } case DHCP_DNSSERVER: GETADDR (dhcp->dnsservers); break; case DHCP_NTPSERVER: GETADDR (dhcp->ntpservers); break; case DHCP_NISSERVER: GETADDR (dhcp->nisservers); break; #undef GETADDR case DHCP_DNSSEARCH: MIN_LENGTH (1); free (dhcp->dnssearch); if ((len = decode_search (p, length, NULL)) > 0) { dhcp->dnssearch = xmalloc (len); decode_search (p, length, dhcp->dnssearch); } break; case DHCP_CSR: MIN_LENGTH (5); free_route (csr); csr = decodeCSR (p, length); break; case DHCP_STATICROUTE: MULT_LENGTH (8); for (i = 0; i < length; i += 8) { if (static_routesp) { static_routesp->next = xmalloc (sizeof (route_t)); static_routesp = static_routesp->next; } else static_routesp = static_routes = xmalloc (sizeof (route_t)); memset (static_routesp, 0, sizeof (route_t)); memcpy (&static_routesp->destination.s_addr, p + i, 4); memcpy (&static_routesp->gateway.s_addr, p + i + 4, 4); static_routesp->netmask.s_addr = getnetmask (static_routesp->destination.s_addr); } break; case DHCP_ROUTERS: MULT_LENGTH (4); for (i = 0; i < length; i += 4) { if (routersp) { routersp->next = xmalloc (sizeof (route_t)); routersp = routersp->next; } else routersp = routers = xmalloc (sizeof (route_t)); memset (routersp, 0, sizeof (route_t)); memcpy (&routersp->gateway.s_addr, p + i, 4); } break; #undef LENGTH #undef MIN_LENGTH #undef MULT_LENGTH default: logger (LOG_DEBUG, "no facility to parse DHCP code %u", option); break; } p += length; } eexit: /* Fill in any missing fields */ if (! dhcp->netmask.s_addr) dhcp->netmask.s_addr = getnetmask (dhcp->address.s_addr); if (! dhcp->broadcast.s_addr) dhcp->broadcast.s_addr = dhcp->address.s_addr | ~dhcp->netmask.s_addr; /* If we have classess static routes then we discard static routes and routers according to RFC 3442 */ if (csr) { dhcp->routes = csr; free_route (routers); free_route (static_routes); } else { /* Ensure that we apply static routes before routers */ if (static_routes) { dhcp->routes = static_routes; static_routesp->next = routers; } else dhcp->routes = routers; } return retval; }
int parse_dhcpmessage (dhcp_t *dhcp, dhcpmessage_t *message) { unsigned char *p = message->options; unsigned char option; unsigned char length; unsigned char *end = message->options + sizeof (message->options); unsigned int len = 0; int i; int retval = -1; route_t *first_route = xmalloc (sizeof (route_t)); route_t *route = first_route; route_t *last_route = NULL; route_t *csr = NULL; char classid[CLASS_ID_MAX_LEN]; char clientid[CLIENT_ID_MAX_LEN]; memset (first_route, 0, sizeof (route_t)); /* The message back never has the class or client id's so we save them */ strcpy (classid, dhcp->classid); strcpy (clientid, dhcp->clientid); free_dhcp (dhcp); memset (dhcp, 0, sizeof (dhcp_t)); dhcp->address.s_addr = message->yiaddr; strcpy (dhcp->servername, message->servername); while (p < end) { option = *p++; if (!option) continue; length = *p++; if (p + length >= end) { retval = -1; goto eexit; } switch (option) { case DHCP_END: goto eexit; case DHCP_MESSAGETYPE: retval = (int) *p; break; #define GET_UINT32(_val) \ memcpy (&_val, p, sizeof (uint32_t)); #define GET_UINT32_H(_val) \ GET_UINT32 (_val); \ _val = ntohl (_val); case DHCP_ADDRESS: GET_UINT32 (dhcp->address.s_addr); break; case DHCP_NETMASK: GET_UINT32 (dhcp->netmask.s_addr); break; case DHCP_BROADCAST: GET_UINT32 (dhcp->broadcast.s_addr); break; case DHCP_SERVERIDENTIFIER: GET_UINT32 (dhcp->serveraddress.s_addr); break; case DHCP_LEASETIME: GET_UINT32_H (dhcp->leasetime); break; case DHCP_RENEWALTIME: GET_UINT32_H (dhcp->renewaltime); break; case DHCP_REBINDTIME: GET_UINT32_H (dhcp->rebindtime); break; case DHCP_MTU: GET_UINT32_H (dhcp->mtu); /* Minimum legal mtu is 68 */ if (dhcp->mtu > 0 && dhcp->mtu < 68) dhcp->mtu = 68; break; #undef GET_UINT32_H #undef GET_UINT32 #define GETSTR(_var) \ if (_var) free (_var); \ _var = xmalloc (length + 1); \ memcpy (_var, p, length); \ memset (_var + length, 0, 1); case DHCP_HOSTNAME: GETSTR (dhcp->hostname); break; case DHCP_DNSDOMAIN: GETSTR (dhcp->dnsdomain); break; case DHCP_MESSAGE: GETSTR (dhcp->message); break; case DHCP_ROOTPATH: GETSTR (dhcp->rootpath); break; case DHCP_NISDOMAIN: GETSTR (dhcp->nisdomain); break; #undef GETSTR #define GETADDR(_var) \ if (_var) free (_var); \ _var = xmalloc (sizeof (address_t)); \ dhcp_add_address (_var, p, length); case DHCP_DNSSERVER: GETADDR (dhcp->dnsservers); break; case DHCP_NTPSERVER: GETADDR (dhcp->ntpservers); break; case DHCP_NISSERVER: GETADDR (dhcp->nisservers); break; #undef GETADDR case DHCP_DNSSEARCH: if (dhcp->dnssearch) free (dhcp->dnssearch); if ((len = decode_search (p, length, NULL))) { dhcp->dnssearch = xmalloc (len); decode_search (p, length, dhcp->dnssearch); } break; case DHCP_CSR: csr = decodeCSR (p, length); break; case DHCP_STATICROUTE: for (i = 0; i < length; i += 8) { memcpy (&route->destination.s_addr, p + i, 4); memcpy (&route->gateway.s_addr, p + i + 4, 4); route->netmask.s_addr = getnetmask (route->destination.s_addr); last_route = route; route->next = xmalloc (sizeof (route_t)); route = route->next; memset (route, 0, sizeof (route_t)); } break; case DHCP_ROUTERS: for (i = 0; i < length; i += 4) { memcpy (&route->gateway.s_addr, p + i, 4); last_route = route; route->next = xmalloc (sizeof (route_t)); route = route->next; memset (route, 0, sizeof (route_t)); } break; default: logger (LOG_DEBUG, "no facility to parse DHCP code %u", option); break; } p += length; } eexit: /* Fill in any missing fields */ if (! dhcp->netmask.s_addr) dhcp->netmask.s_addr = getnetmask (dhcp->address.s_addr); if (! dhcp->broadcast.s_addr) dhcp->broadcast.s_addr = dhcp->address.s_addr | ~dhcp->netmask.s_addr; /* If we have classess static routes then we discard static routes and routers according to RFC 3442 */ if (csr) { dhcp->routes = csr; free_route (first_route); } else { dhcp->routes = first_route; if (last_route) { free (last_route->next); last_route->next = NULL; } else { free_route (dhcp->routes); dhcp->routes = NULL; } } /* The message back never has the class or client id's so we restore them */ strcpy (dhcp->classid, classid); strcpy (dhcp->clientid, clientid); return retval; }
void *htext_copy_method(void *h) { htext_handle *handle = (htext_handle*)h; CURL *curl; char *delegation_id = NULL, *location; htext_partial control; char buffer[CURL_MAX_WRITE_SIZE], err_buffer[CURL_ERROR_SIZE]; char host[64]; /* Create and initialize CURL handle */ curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_buffer); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, htext_header_callback); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, htext_write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &control); curl_easy_setopt(curl, CURLOPT_URL, GETSTR(handle, HTEXTOP_SOURCEURL)); curl_easy_setopt(curl, CURLOPT_USERAGENT, GETSTR(handle, HTEXTOP_CLIENTID)); curl_easy_setopt(curl, CURLOPT_CAPATH, GETSTR(handle, HTEXTOP_CAPATH)); curl_easy_setopt(curl, CURLOPT_CAINFO, GETSTR(handle, HTEXTOP_CAFILE)); curl_easy_setopt(curl, CURLOPT_SSLCERT, GETSTR(handle, HTEXTOP_USERCERTIFICATE)); curl_easy_setopt(curl, CURLOPT_SSLKEY, GETSTR(handle, HTEXTOP_USERPRIVKEY)); curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, GETSTR(handle, HTEXTOP_USERPRIVKEYPASS)); if (GETINT(handle, HTEXTOP_VERBOSITY) > 1) { curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, htext_debug_callback); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } curl_easy_setopt(curl, CURLOPT_SHARE, handle->curl_share); /* Reserve space for the partials */ handle->partial_done = calloc(sizeof(size_t), 1); handle->partial_total = calloc(sizeof(size_t), 1); handle->partials = 1; /* Do a HEAD to know where do we have to go */ htext_partial_init(&control); control.partial_total = handle->partial_total; control.partial_done = handle->partial_done; control.handle = handle; curl_easy_setopt(curl, CURLOPT_NOBODY, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_HEADERDATA, &control); curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &control); handle->status = HTEXTS_WAITING; htext_log(handle, "Retrieving the actual location"); if (curl_easy_perform(curl) != CURLE_OK) htext_error(handle, buffer); /* If we got it, delegate */ if (handle->status != HTEXTS_FAILED && control.location) location = control.location; else htext_error(handle, "Could not get the location"); /* Delegate */ if (handle->status != HTEXTS_FAILED) { /* Pick from configuration if not available */ if (control.delegation_service == NULL) { control.delegation_service = GETSTR(handle, HTEXTOP_DELEGATION_URL); } /* Not yet? */ if (control.delegation_service == NULL) { htext_error(handle, "Could not get the delegation endpoint"); } /* Build the full URL */ else { snprintf(buffer, sizeof(buffer), "https://%s%s", get_host(location, host), control.delegation_service); htext_log(handle, "Delegation endpoint: %s", buffer); delegation_id = htext_delegate(handle, buffer, err_buffer); htext_log(handle, "Got delegation id %s", delegation_id); } } /* Do the COPY */ if (handle->status != HTEXTS_FAILED) { char *full_url; htext_log(handle, "Running the remote copy"); handle->status = HTEXTS_RUNNING; full_url = malloc(strlen(location) + strlen(delegation_id) + 14); /* Beware: when copying, the user cert is needed, so ignore http:// prefixes, * and assume https:// */ if (strncmp(location, "http:", 5) == 0) { sprintf(full_url, "https:%s&delegation=%s", location + 5, delegation_id); } else { sprintf(full_url, "%s&delegation=%s", location, delegation_id); } curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "COPY"); curl_easy_setopt(curl, CURLOPT_URL, full_url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, htext_copy_write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &control); /* Need to flush often to get progress */ curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 64); snprintf(buffer, sizeof(buffer), "Destination: %s", GETSTR(handle, HTEXTOP_DESTINATIONURL)); control.headers = curl_slist_append(control.headers, buffer); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, control.headers); control.http_status = 0; /* Reset this */ control.extra = buffer; buffer[0] = '\0'; if (curl_easy_perform(curl) != CURLE_OK) { htext_error(handle, err_buffer); } else if (control.http_status >= 400 || handle->status == HTEXTS_FAILED) { htext_error(handle, NULL); } else { handle->status = HTEXTS_SUCCEEDED; } handle->http_status = control.http_status; free(full_url); } /* Clean up */ free(delegation_id); htext_partial_clean(&control); curl_easy_cleanup(curl); return NULL; }
/** * Do the delegation * @param handle The handle * @param url The delegation endpoint * @param err_buffer Used to build the error string * @return NULL on failure, or an allocated string with the delegation ID */ static char *htext_delegate(htext_handle *handle, char *url, char *err_buffer) { char *delegation_id = NULL; char *reqtxt = NULL, *certtxt = NULL; char *keycert = NULL; struct soap *soap_get = NULL, *soap_put = NULL; struct tns__getNewProxyReqResponse getNewProxyReqResponse; char *ucert = NULL, *ukey = NULL, *capath = NULL; int lifetime; /* Get from the handle */ ucert = GETSTR(handle, HTEXTOP_USERCERTIFICATE); ukey = GETSTR(handle, HTEXTOP_USERPRIVKEY); capath = GETSTR(handle, HTEXTOP_CAPATH); lifetime = GETINT(handle, HTEXTOP_PROXYLIFE); /* Only one is needed if they are the same */ if (ucert && !ukey) ukey = ucert; if (!ucert && ukey) ucert = ukey; /* Cert and key need to be in the same file */ if (strcmp(ucert, ukey) == 0) { keycert = strdup(ucert); } else { FILE *ifp, *ofp; int fd; char c; keycert = strdup("/tmp/.XXXXXX"); fd = mkstemp(keycert); ofp = fdopen(fd, "w"); ifp = fopen(ukey, "r"); while ((c = fgetc(ifp)) != EOF) fputc(c, ofp); fclose(ifp); ifp = fopen(ukey, "r"); while ((c = fgetc(ifp)) != EOF) fputc(c, ofp); fclose(ifp); fclose(ofp); } /* Initialize SSL */ ERR_load_crypto_strings (); OpenSSL_add_all_algorithms(); /* Request a new delegation ID */ soap_get = soap_new(); if (soap_ssl_client_context(soap_get, SOAP_SSL_DEFAULT, keycert, "", NULL, capath, NULL) == 0) { soap_call_tns__getNewProxyReq(soap_get, url, "http://www.gridsite.org/namespaces/delegation-1", &getNewProxyReqResponse); if(soap_get->error == 0) { reqtxt = getNewProxyReqResponse.getNewProxyReqReturn->proxyRequest; delegation_id = strdup(getNewProxyReqResponse.getNewProxyReqReturn->delegationID); /* Generate proxy */ if (GRSTx509MakeProxyCert(&certtxt, stderr, reqtxt, ucert, ukey, lifetime) == GRST_RET_OK) { /* Submit the proxy */ soap_put = soap_new(); if (soap_ssl_client_context(soap_put, SOAP_SSL_DEFAULT, keycert, "", NULL, capath, NULL) == 0) { soap_call_tns__putProxy(soap_put, url, "http://www.gridsite.org/namespaces/delegation-1", delegation_id, certtxt, NULL); if (soap_put->error) { /* Could not PUT */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_put, stderr); handle->status = HTEXTS_FAILED; #endif } } else { /* soap_put ssl error */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_put, stderr); handle->status = HTEXTS_FAILED; #endif } soap_free(soap_put); } else { htext_error(handle, "Could not generate the proxy"); } } else { /* Could not get ID */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_get, stderr); handle->status = HTEXTS_FAILED; #endif } } else { /* soap_get ssl error */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_put, stderr); handle->status = HTEXTS_FAILED; #endif } /* Clean soap_get */ soap_free(soap_get); free(keycert); free(certtxt); /* Return delegation ID */ return delegation_id; }
void disklabel_edit(struct disklabel *lp) { int i; printf("Select disk type. Valid types:\n"); for (i = 0; i < DKMAXTYPES; i++) printf("%d %s\n", i, dktypenames[i]); printf("\n"); GETNUM("Disk type (number)? [%d] ", lp->d_type); GETSTR("Disk model name? [%s] ", lp->d_typename); GETSTR("Disk pack name? [%s] ", lp->d_packname); FLAGS("Bad sectoring? [%c] ", D_BADSECT); FLAGS("Ecc? [%c] ", D_ECC); FLAGS("Removable? [%c] ", D_REMOVABLE); printf("\n"); GETNUM("Interleave? [%d] ", lp->d_interleave); GETNUM("Rpm? [%d] ", lp->d_rpm); GETNUM("Trackskew? [%d] ", lp->d_trackskew); GETNUM("Cylinderskew? [%d] ", lp->d_cylskew); GETNUM("Headswitch? [%d] ", lp->d_headswitch); GETNUM("Track-to-track? [%d] ", lp->d_trkseek); GETNUM("Drivedata 0? [%d] ", lp->d_drivedata[0]); GETNUM("Drivedata 1? [%d] ", lp->d_drivedata[1]); GETNUM("Drivedata 2? [%d] ", lp->d_drivedata[2]); GETNUM("Drivedata 3? [%d] ", lp->d_drivedata[3]); GETNUM("Drivedata 4? [%d] ", lp->d_drivedata[4]); printf("\n"); GETNUM("Bytes/sector? [%d] ", lp->d_secsize); GETNUM("Sectors/track? [%d] ", lp->d_nsectors); GETNUM("Tracks/cylinder? [%d] ", lp->d_ntracks); if (lp->d_secpercyl == 0) lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; GETNUM("Sectors/cylinder? [%d] ", lp->d_secpercyl); GETNUM("Cylinders? [%d] ", lp->d_ncylinders); if (lp->d_secperunit == 0) lp->d_secperunit = lp->d_ncylinders * lp->d_secpercyl; GETNUM("Total sectors? [%d] ", lp->d_secperunit); printf( "Enter partition table. Note, sizes and offsets are in sectors.\n\n"); lp->d_npartitions = MAXPARTITIONS; for (i = 0; i < lp->d_npartitions; ++i) { GETNUM2("%c partition: offset? [%d] ", ('a' + i), lp->d_partitions[i].p_offset); GETNUM(" size? [%d] ", lp->d_partitions[i].p_size); get_fstype(lp, i); } /* Perform magic. */ lp->d_magic = lp->d_magic2 = DISKMAGIC; /* Calculate disklabel checksum. */ lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); }