99 * | BingChunMoLi <[email protected] > 1010 * |
1111 * Created On : <2023-08-28>
12- * Last Modified : <2025-10-07 >
12+ * Last Modified : <2025-10-15 >
1313 *
1414 *
1515 * xy: 襄阳、咸阳
@@ -122,15 +122,24 @@ xy =
122122
123123#define assert_str (a , b ) assert (xy_streql ((a), (b)))
124124
125- #define xy_panic (reason ) assert(!reason)
125+ #define xy_throw (reason ) assert(!reason)
126126
127- // @flavor Perl, PHP, Raku
128- #define die xy_panic
127+ /**
128+ * @depreacated 避免消极用语
129+ *
130+ * @flavor Perl, PHP, Raku
131+ */
132+ // #define die xy_throw
129133
130- #define xy_unsupported () xy_panic("Unsuppoted")
131- #define xy_unimplemented () xy_panic("Unimplemented temporarily")
132- #define xy_unreached () xy_panic("This code shouldn't be reached")
133- #define xy_cant_be_null (p ) if(!p) xy_panic("This pointer can't be null")
134+ /**
135+ * @depreacated 避免消极用语
136+ */
137+ // #define xy_panic xy_throw
138+
139+ #define xy_unsupported () xy_throw("Unsuppoted")
140+ #define xy_unimplemented () xy_throw("Unimplemented temporarily")
141+ #define xy_unreached () xy_throw("This code shouldn't be reached")
142+ #define xy_cant_be_null (p ) if(!p) xy_throw("This pointer can't be null")
134143
135144
136145
@@ -164,7 +173,7 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);}
164173 bool: _xy_print_bool, \
165174 char *: _xy_print_str, \
166175 const char *: _xy_print_const_str, \
167- default: xy_panic ("Unsupported type for print()!") \
176+ default: xy_throw ("Unsupported type for print()!") \
168177)(x)
169178
170179/**
@@ -179,7 +188,7 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);}
179188 bool: _xy_println_bool, \
180189 char *: _xy_println_str, \
181190 const char *: _xy_println_const_str, \
182- default: xy_panic ("Unsupported type for println()/say()!") \
191+ default: xy_throw ("Unsupported type for println()/say()!") \
183192)(x)
184193/* @flavor Raku, Perl */
185194#define say println
@@ -1332,18 +1341,21 @@ xy_detect_os ()
13321341 char buf [256 ] = {0 };
13331342 fread (buf , 1 , sizeof (buf ) - 1 , fp );
13341343 fclose (fp );
1335- if (strstr (buf , "Android" ))
1336- {
1337- xy .on_android = true;
1338- return ;
1339- }
1340- else if (strstr (buf , "Linux" ))
1344+ if (strstr (buf , "Linux" ))
13411345 {
13421346 xy .on_linux = true;
13431347 return ;
13441348 }
13451349 }
13461350
1351+ // @consult https://android.googlesource.com/platform/system/core/+/refs/heads/main/rootdir/init.environ.rc.in
1352+ char * android_env = getenv ("ANDROID_ROOT" );
1353+ if (xy_str_find (android_env , "/system" ).found )
1354+ {
1355+ xy .on_android = true;
1356+ return ;
1357+ }
1358+
13471359 /* 判断 macOS */
13481360 DIR * d = opendir ("/System/Applications" );
13491361 if (d )
@@ -1354,6 +1366,7 @@ xy_detect_os ()
13541366 {
13551367 xy .on_macos = true;
13561368 closedir (d );
1369+ return ;
13571370 }
13581371 }
13591372
@@ -1376,10 +1389,11 @@ xy_detect_os ()
13761389 pclose (fp );
13771390 if (strstr (buf , "BSD" ) != NULL )
13781391 xy .on_bsd = true;
1392+ return ;
13791393 }
13801394
13811395 if (!(xy .on_windows || xy .on_linux || xy .on_android || xy .on_macos || xy .on_bsd ))
1382- xy_panic ("Unknown operating system" );
1396+ xy_throw ("Unknown operating system" );
13831397}
13841398
13851399
@@ -1488,7 +1502,7 @@ xy_seq_at (XySeq_t *seq, int n)
14881502{
14891503 xy_cant_be_null (seq );
14901504
1491- if (0 == n ) xy_panic ("The index must begin from 1, not 0" );
1505+ if (0 == n ) xy_throw ("The index must begin from 1, not 0" );
14921506
14931507 if (1 == n ) return seq -> first_item ? seq -> first_item -> data : NULL ;
14941508
0 commit comments