< prev index next >

src/java.base/share/native/libjli/args.c

Print this page
rev 57595 : imported patch 8240629.fix


 201                     case 't':
 202                         escaped[0] = '\t';
 203                         break;
 204                     case 'f':
 205                         escaped[0] = '\f';
 206                         break;
 207                     default:
 208                         escaped[0] = ch;
 209                         break;
 210                 }
 211                 JLI_List_add(pctx->parts, escaped);
 212                 pctx->state = IN_QUOTE;
 213             }
 214             // anchor to next character
 215             anchor = nextc + 1;
 216             continue;
 217         // ignore comment to EOL
 218         } else if (pctx->state == IN_COMMENT) {
 219             while (ch != '\n' && ch != '\r') {
 220                 nextc++;
 221                 if (nextc > eob) {
 222                     return NULL;
 223                 }
 224                 ch = *nextc;
 225             }

 226             pctx->state = FIND_NEXT;
 227             continue;
 228         }
 229 
 230         assert(pctx->state != IN_ESCAPE);
 231         assert(pctx->state != FIND_NEXT);
 232         assert(pctx->state != SKIP_LEAD_WS);
 233         assert(pctx->state != IN_COMMENT);
 234 
 235         switch(ch) {
 236             case ' ':
 237             case '\t':
 238             case '\f':
 239                 if (pctx->state == IN_QUOTE) {
 240                     continue;
 241                 }
 242                 // fall through
 243             case '\n':
 244             case '\r':
 245                 if (pctx->parts->size == 0) {


 276                 }
 277                 // partial before quote
 278                 if (anchor != nextc) {
 279                     JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
 280                 }
 281                 // anchor after quote character
 282                 anchor = nextc + 1;
 283                 if (pctx->state == IN_TOKEN) {
 284                     pctx->quote_char = ch;
 285                     pctx->state = IN_QUOTE;
 286                 } else {
 287                     pctx->state = IN_TOKEN;
 288                 }
 289                 break;
 290             default:
 291                 break;
 292         }
 293     }
 294 
 295     assert(nextc == eob);
 296     if (anchor != nextc) {
 297         // not yet return until end of stream, we have part of a token.
 298         JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
 299     }
 300     return NULL;
 301 }
 302 
 303 static JLI_List readArgFile(FILE *file) {
 304     char buf[4096];
 305     JLI_List rv;
 306     __ctx_args ctx;
 307     size_t size;
 308     char *token;
 309 
 310     ctx.state = FIND_NEXT;
 311     ctx.parts = JLI_List_new(4);
 312     // initialize to avoid -Werror=maybe-uninitialized issues from gcc 7.3 onwards.
 313     ctx.quote_char = '"';
 314 
 315     /* arbitrarily pick 8, seems to be a reasonable number of arguments */
 316     rv = JLI_List_new(8);




 201                     case 't':
 202                         escaped[0] = '\t';
 203                         break;
 204                     case 'f':
 205                         escaped[0] = '\f';
 206                         break;
 207                     default:
 208                         escaped[0] = ch;
 209                         break;
 210                 }
 211                 JLI_List_add(pctx->parts, escaped);
 212                 pctx->state = IN_QUOTE;
 213             }
 214             // anchor to next character
 215             anchor = nextc + 1;
 216             continue;
 217         // ignore comment to EOL
 218         } else if (pctx->state == IN_COMMENT) {
 219             while (ch != '\n' && ch != '\r') {
 220                 nextc++;
 221                 if (nextc >= eob) {
 222                     return NULL;
 223                 }
 224                 ch = *nextc;
 225             }
 226             anchor = nextc + 1;
 227             pctx->state = FIND_NEXT;
 228             continue;
 229         }
 230 
 231         assert(pctx->state != IN_ESCAPE);
 232         assert(pctx->state != FIND_NEXT);
 233         assert(pctx->state != SKIP_LEAD_WS);
 234         assert(pctx->state != IN_COMMENT);
 235 
 236         switch(ch) {
 237             case ' ':
 238             case '\t':
 239             case '\f':
 240                 if (pctx->state == IN_QUOTE) {
 241                     continue;
 242                 }
 243                 // fall through
 244             case '\n':
 245             case '\r':
 246                 if (pctx->parts->size == 0) {


 277                 }
 278                 // partial before quote
 279                 if (anchor != nextc) {
 280                     JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
 281                 }
 282                 // anchor after quote character
 283                 anchor = nextc + 1;
 284                 if (pctx->state == IN_TOKEN) {
 285                     pctx->quote_char = ch;
 286                     pctx->state = IN_QUOTE;
 287                 } else {
 288                     pctx->state = IN_TOKEN;
 289                 }
 290                 break;
 291             default:
 292                 break;
 293         }
 294     }
 295 
 296     assert(nextc == eob);
 297     if (anchor < nextc) {
 298         // not yet return until end of stream, we have part of a token.
 299         JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
 300     }
 301     return NULL;
 302 }
 303 
 304 static JLI_List readArgFile(FILE *file) {
 305     char buf[4096];
 306     JLI_List rv;
 307     __ctx_args ctx;
 308     size_t size;
 309     char *token;
 310 
 311     ctx.state = FIND_NEXT;
 312     ctx.parts = JLI_List_new(4);
 313     // initialize to avoid -Werror=maybe-uninitialized issues from gcc 7.3 onwards.
 314     ctx.quote_char = '"';
 315 
 316     /* arbitrarily pick 8, seems to be a reasonable number of arguments */
 317     rv = JLI_List_new(8);


< prev index next >