.\" -*- coding: UTF-8 -*- '\" t .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH getopt_long 3 "14 فبراير 2026" "صفحات دليل لينكس 6.18" .SH الاسم getopt_long \- يُحلل خيارات سطر الأوامر .SH المكتبة مكتبة سي المعيارية (\fIlibc\fP،\ \fI\-lc\fP) .SH موجز .nf \fB#define _GNU_SOURCE\fP \fB#include \fP .P \fBint getopt_long(int \fP\fIargc\fP\fB, char *\fP\fIargv\fP\fB[],\fP \fB const char *\fP\fIoptstring\fP\fB,\fP \fB const struct option *\fP\fIlongopts\fP\fB, int *\fP\fIlongindex\fP\fB);\fP .fi .SH الوصف تعمل الدالة \fBgetopt_long\fP() مثل \fBgetopt\fP(3) باستثناء أنها تقبل أيضًا خيارات طويلة، تبدأ بشرطتين. (إذا كان البرنامج يقبل الخيارات الطويلة فقط، فيجب تحديد \fIoptstring\fP كسلسلة نصية فارغة ("")، وليس NULL.) يمكن اختصار أسماء الخيارات الطويلة إذا كان الاختصار فريدًا أو مطابقًا تمامًا لبعض الخيارات المحددة. قد يأخذ الخيار الطويل معاملًا، على الشكل \fB\-\-arg=param\fP أو \fB\-\-arg param\fP. .P \fIlongopts\fP هو مؤشر للعنصر الأول من مصفوفة من \fIstruct option\fP مُصرح عنها في \fI\fP كـ .P .in +4n .EX struct option { const char *name; int has_arg; int *flag; int val; }; .EE .in .P معاني الحقول المختلفة هي: .TP \fIname\fP هو اسم الخيار الطويل. .TP \fIhas_arg\fP هو: \fBno_argument\fP (أو 0) إذا كان الخيار لا يأخذ معاملًا؛ أو \fBrequired_argument\fP (أو 1) إذا كان الخيار يتطلب معاملًا؛ أو \fBoptional_argument\fP (أو 2) إذا كان الخيار يأخذ معاملًا اختياريًا. .TP \fIflag\fP يحدد كيفية إرجاع النتائج للخيار الطويل. إذا كان \fIflag\fP هو NULL، فإن \fBgetopt_long\fP() تُرجع \fIval\fP. (على سبيل المثال، قد يضبط البرنامج المستدعِي \fIval\fP على محرف الخيار القصير المكافئ.) خلاف ذلك، تُرجع \fBgetopt_long\fP() القيمة 0، ويشير \fIflag\fP إلى متغير يُضبط على \fIval\fP إذا عُثر على الخيار، ولكنه يُترك دون تغيير إذا لم يُعثر على الخيار. .TP \fIval\fP هي القيمة المراد إرجاعها، أو تحميلها في المتغير الذي يشير إليه \fIflag\fP. .P يجب ملء العنصر الأخير من المصفوفة بالأصفار. .P إذا لم يكن \fIlongindex\fP هو NULL، فإنه يشير إلى متغير يُضبط على فهرس الخيار الطويل بالنسبة إلى \fIlongopts\fP. .P نظيره لـ \fIoptopt\fP في \fBgetopt\fP(3) هو \[lq]\fIargv[(optind \- 1)]\fP\[rq]. .SH "قيمة الإرجاع" انظر \fBgetopt\fP(3). .P تُرجع \fBgetopt_long\fP() أيضًا محرف الخيار عند التعرف على خيار قصير. بالنسبة للخيار الطويل، فإنها تُرجع \fIval\fP إذا كان \fIflag\fP هو NULL، و 0 خلاف ذلك. قيم إرجاع الخطأ و \-1 هي نفسها كما في \fBgetopt\fP(3)، بالإضافة إلى \[aq]?\[aq] للمطابقة الغامضة أو المعاملات الزائدة. .SH البيئة انظر \fBgetopt\fP(3). .SH السمات للاطلاع على شرح للمصطلحات المستخدمة في هذا القسم، انظر \fBattributes\fP(7). .TS allbox; lb lb lbx l l l. الواجهة السمة القيمة T{ .na .nh \fBgetopt_long\fP() T} سلامة الخيوط T{ .na .nh غير آمن للمسارات المتعددة (MT\-Unsafe) سباق:getopt env T} .TE .SH المعايير GNU. .SH أمثلة يوضح البرنامج المثال التالي استخدام \fBgetopt_long\fP() مع معظم ميزاتها. .P .\" SRC BEGIN (getopt_long.c) .EX #include #include #include #include \& int main(int argc, char *argv[]) { int c; int digit_optind = 0; \& for (;;) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { {"add", required_argument, 0, 0 }, {"append", no_argument, 0, 0 }, {"delete", required_argument, 0, 0 }, {"verbose", no_argument, 0, 0 }, {"create", required_argument, 0, \[aq]c\[aq]}, {"file", required_argument, 0, 0 }, {0, 0, 0, 0 } }; \& c = getopt_long(argc, argv, "abc:d:012", long_options, &option_index); if (c == \-1) break; \& switch (c) { case 0: printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\[rs]n"); break; \& case \[aq]0\[aq]: case \[aq]1\[aq]: case \[aq]2\[aq]: if (digit_optind != 0 && digit_optind != this_option_optind) printf("digits occur in two different argv\-elements.\[rs]n"); digit_optind = this_option_optind; printf("option %c\[rs]n", c); break; \& case \[aq]a\[aq]: printf("option a\[rs]n"); break; \& case \[aq]b\[aq]: printf("option b\[rs]n"); break; \& case \[aq]c\[aq]: printf("option c with value \[aq]%s\[aq]\[rs]n", optarg); break; \& case \[aq]d\[aq]: printf("option d with value \[aq]%s\[aq]\[rs]n", optarg); break; \& case \[aq]?\[aq]: break; \& default: printf("?? getopt returned character code 0%o ??\[rs]n", c); } } \& if (optind < argc) { printf("non\-option ARGV\-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\[rs]n"); } \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "انظر أيضًا" \fBgetopt\fP(1), \fBgetopt\fP(3), \fBgetopt_long_only\fP(3), \fBgetsubopt\fP(3) .PP .SH ترجمة تُرجمت هذه الصفحة من الدليل بواسطة زايد السعيدي . .PP هذه الترجمة هي وثيقة مجانية؛ راجع .UR https://www.gnu.org/licenses/gpl-3.0.html رخصة جنو العامة الإصدار 3 .UE أو ما بعده للاطلاع على شروط حقوق النشر. لا توجد أي ضمانات. .PP إذا وجدت أي أخطاء في ترجمة صفحة الدليل هذه، يرجى إرسال بريد إلكتروني إلى قائمة بريد المترجمين: .MT kde-l10n-ar@kde.org .ME .